Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to overwrite constructor on defdata inside defsum #18

Open
OvermindDL1 opened this issue Jul 7, 2017 · 1 comment
Open

Unable to overwrite constructor on defdata inside defsum #18

OvermindDL1 opened this issue Jul 7, 2017 · 1 comment

Comments

@OvermindDL1
Copy link

Unable to overwrite constructor on defdata inside defsum.

Precisely that, as from the examples with an overwrite added as per the defdata section:

defmodule Pet do
  defsum do
    defdata Cat do
      name :: String.t()
      claw_sharpness :: String.t()

      def new(name, clawness) when byte_size(name)>=3, do: %Cat{name: value, claw_sharpness: clawness}
    end

    defdata Dog do
      name :: String.t()
      bark_loudness :: non_neg_integer()

      def new(name, barkness) when byte_size(name)>=3, do: %Dog{name: value, bark_loudness: barkness}
    end
  end
end

Fails to compile with a message of like: (though from my code):

** (FunctionClauseError) no function clause matching in Algae.Internal.normalize_elements/1
    lib/algae/internal.ex:149: Algae.Internal.normalize_elements({:def, [line: 28], [{:when, [line: 28], [{:new, [line: 28], [{:type, [line: 28], nil}, {:\\, [line: 28], [{:meta, [line: 28], nil}, {:%{}, [line: 28], []}]}]}, {:and, [line: 28], [{:is_map, [line: 28], [{:meta, [line: 28], nil}]}, {:in, [line: 28], [{:type, [line: 28], nil}, {:@, [line: 28], [{:const_types, [line: 28], nil}]}]}]}]}, [do: {:%, [line: 28], [{:__aliases__, [counter: 0, line: 28], [:TConst]}, {:%{}, [line: 28], [type: {:type, [line: 28], nil}, meta: {:meta, [line: 28], nil}]}]}]]})
    lib/algae/internal.ex:135: anonymous fn/2 in Algae.Internal.module_elements/1
    (elixir) lib/list.ex:200: List."-foldr/3-lists^foldr/2-0-"/3
    lib/algae/internal.ex:11: Algae.Internal.data_ast/1
    expanding macro: Algae.defdata/2
    lib/ml_elixir/types.ex:25: MlElixir.Types (module)
    expanding macro: Algae.defsum/1
    lib/ml_elixir/types.ex:19: MlElixir.Types (module)

We can define it outside but then that just puts a struct in a struct, which is noisy indirection.

@hauleth
Copy link

hauleth commented Aug 16, 2018

It would be also handy to support module attributes to support @moduledoc and @derive at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants