serde-ml / serde

Serialization framework for OCaml
MIT License
174 stars 11 forks source link

Unable to derive deserializer for a list type alias #30

Closed emilpriver closed 6 months ago

emilpriver commented 6 months ago

I am unable to creating a deriving list type when deserializing data

The code:


type user = {
  id: int;
  name: string;
  some_bool: bool;
  pet_name: string option;
  some_int64: int64;
  some_int32: int32;
  some_float: float;
  pets: string list;
  pets_array: string array;
}
[@@deriving deserialize]

type users = user list [@@deriving deserialize]

The error message.

File "serde-postgres/test/test_serde.ml", line 33, characters 0-47:
33 | type users = user list [@@deriving deserialize]
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This expression has type string
       This is not a function; it cannot be applied.

This is the same when I am using an array

File "serde-postgres/test/test_serde.ml", line 33, characters 0-48:
33 | type users = user array [@@deriving deserialize]
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This expression has type string
       This is not a function; it cannot be applied.

Source code: https://github.com/dbcaml/dbcaml/blob/2e2fab3ea4b8d9b4bd6d7108ea6548f1fce51d4f/serde-postgres/test/test_serde.ml#L20-L33

Reproducing

The simplest way to reproduce is to clone gbcaml:

git clone github.com/dbcaml/dbcaml

and checkout to either branch v2 or sha 2e2fab3ea4b8d9b4bd6d7108ea6548f1fce51d4f.

You should be able to do

opam install . --deps-only

and get all the packages needed.

run the test with: dune runtest

linear[bot] commented 6 months ago

RIOT-29 Unable to create a list type

emilpriver commented 6 months ago

I added reproducing step, let me know if it don't work. I am going on vacation tomorrow until Sunday so I am not able to look into this myself until next week