- 
                Notifications
    
You must be signed in to change notification settings  - Fork 3.5k
 
Type checking of protocol dispatch #14117
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
Conversation
| #{hint()} string interpolation in Elixir uses the String.Chars protocol to \ | ||
| convert a data structure into a string. Either convert the data type into a \ | ||
| string upfront or implement the protocol accordingly | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we suggest for which type to implement this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately no, because there may be an infinite amount of them. If someone has a type of not Range.t, it can be any other struct, which wouldn't be valid in String.Chars (and some structs definitely do not implemnt String.Chars , but we also cannot list them).
| {{:., _, [mod, fun]}, meta, args} -> erl_to_ex(mod, fun, args, meta) | ||
| other -> other | ||
| {:%, _, [Range, {:%{}, _, fields}]} = node -> | ||
| case :lists.usort(fields) do | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would maps:from_list/1 here make this code easier to read, so that we don't need to do the mental math to check that the fields below are ordered? 😬
We now type check arguments given to a protocol. The following code:
emits this warning:
We specially handle string interpolations to provide a better experience. So if we replace
to_string(1..3)by"#{1..3}", we will this warning instead:TODO