-
Notifications
You must be signed in to change notification settings - Fork 25
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
Think about if it might at all be possible to support @type t :: %__MODULE__{}
even above a defstruct
#83
Comments
I think this may be related to an issue I was running into with Ecto. Using Ecto's schema "users" do
field :name, :string
end means I automatically get However, if I define @type! t :: %__MODULE__{}
schema "users" do
field :name, :string
end I get an error telling me to move it below the defstruct. It works fine if I do schema "users" do
field :name, :string
end
@type! t :: %__MODULE__{} |
Yes, this is indeed exactly the same situation. |
Are there any abilities to effectively move the position of the |
🤔 I have a new idea to try out: Currently a struct is rewritten into a fixed_map-type exactly at the point where the type is constructed. This requires the struct definition itself to be available at the time the datastructure containing the type-information is constructed. |
Interesting. Do you mean similar to this sort of thing?... #21 |
For now, I think that having A fix is definitely possible, but it will require quite a bit of work and I am not sure that it is worth the effort unless people are very frequently burnt/confused by this problem. If it turns out to be a big problem in practice for people starting to use TypeCheck, then it is worth revisiting this issue. |
With the older checking implementation, this 'sort of' worked but silently did something not fully according to Elixir's typespec rules.
With the new checking implementation of the last minor revision, struct types were broken (c.f. #78 ).
The fix (#82) uncovered a related issue however: It is very common to write something like
however this will currently fail with a compiler error.
What works, is:
but I believe most style guides prefer the former, so a lot of code in the wild will use the former.
I'm not sure what, if at all, we can change to accommodate this, but it needs some thought.
The text was updated successfully, but these errors were encountered: