Skip to content

type errors in handwritten conversion function result in weird error #69

@EmileTrotignon

Description

@EmileTrotignon
type mytype = Int64.t

let mytype_of_json = function
  | `Float f -> Int64.of_float f
  | json -> raise (Melange_json.of_json_error ~json "expected a float")

let mytype_to_json i = Int64.to_string i

type my_record = {
  a : string;
  my_value : mytype;
  b : string;
}
[@@deriving json]

gives the error :

Error: This expression has type (string * [> `String of string ]) list
       but an expression was expected of type (string * string) list
       Type [> `String of string ] is not compatible with type string 

located on the whole of the my_record type definition.

This is quite confusing when the actual error is that mytype_to_json does not return a json but a string. I don't know if something can be done about the location of the error, but at a type constraint could be put on the usage of mytype_to_json so that is error is more like expected Melange_json.t, got string instead of mentioning a tuple and a list.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions