-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Check map updates #10316
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
Check map updates #10316
Conversation
|
|
||
| assert {:error, | ||
| {:unable_unify, | ||
| {{:map, [{:required, {:atom, :bar}, :dynamic}, {:optional, :dynamic, :dynamic}]}, |
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.
The downside with using dynamic() for the values is that it shows up in the error messages which could be slightly confusing.
lib/elixir/lib/module/types/expr.ex
Outdated
| arg_pairs = pairs_to_unions(arg_pairs, context), | ||
| dynamic_value_pairs = | ||
| Enum.map(arg_pairs, fn {:required, key, _value} -> {:required, key, :dynamic} end), | ||
| args_type = {:map, dynamic_value_pairs ++ [{:optional, :dynamic, :dynamic}]}, |
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.
I think we can encapsule the last three lines or so in a function.
lib/elixir/lib/module/types/expr.ex
Outdated
| Enum.map(arg_pairs, fn {:required, key, _value} -> {:required, key, :dynamic} end), | ||
| args_type = {:map, dynamic_value_pairs ++ [{:optional, :dynamic, :dynamic}]}, | ||
| {:ok, type, context} <- unify(args_type, map_type, stack, context) do | ||
| {:map, pairs} = resolve_var(type, context) |
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.
This can return a union if we do: map.foo or map.bar in a guard and then we update the map. So we need to handle this case too.
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.
It can't return a union yet afaict, not until unions are lifted unification. It's hard to tell how to handle this scenario correctly until they unions are lifted. Did you have anything in mind?
Co-authored-by: Eksperimental <eksperimental@users.noreply.github.com>
Co-authored-by: Fernando Tapia Rico <fertapric@gmail.com>
No description provided.