bamorim / typed_ecto_schema

A library to define Ecto schemas with typespecs without all the boilerplate code.
https://hexdocs.pm/typed_ecto_schema
Apache License 2.0
271 stars 18 forks source link

embeds_many required passing an empty list as options #11

Closed dvic closed 2 years ago

dvic commented 3 years ago

Haven't looked into this yet but the following gives the compile error shown below it

  defmodule InlineEmbedsMany do
    use TypedEctoSchema

    @primary_key false
    typed_embedded_schema do
      embeds_many(:many, Many) do
        field(:int, :integer) :: non_neg_integer() | nil

        def get_types, do: Enum.reverse(@__typed_ecto_schema_types__)
      end
    end

    def get_types, do: Enum.reverse(@__typed_ecto_schema_types__)
  end
== Compilation error in file test/typed_ecto_schema_test.exs ==
** (CompileError) test/typed_ecto_schema_test.exs:538: misplaced operator ::/2

The :: operator is typically used in bitstrings to specify types and sizes of segments:

    <<size::32-integer, letter::utf8, rest::binary>>

It is also used in typespecs, such as @type and @spec, to describe inputs and outputs
    (stdlib 3.14) lists.erl:1358: :lists.mapfoldl/3
    (stdlib 3.14) lists.erl:1359: :lists.mapfoldl/3
    (stdlib 3.14) lists.erl:1358: :lists.mapfoldl/3
    (stdlib 3.14) lists.erl:1359: :lists.mapfoldl/3
    (ecto 3.5.6) expanding macro: Ecto.Schema.embedded_schema/1

The original test uses embeds_many(:many, Many, []) and that works just fine.

bamorim commented 3 years ago

I'll take a look at that as soon as possible. Sorry for not noticing it, GitHub notifications are just a mess sometimes.

I think the problem here is that I'm not recursively applying my syntax sugar on top of the nested defined types.

As a workaround for now (not ideal, sorry) you can define Many in a different module and then doing embeds_many(:many, Many).