Skip to content

Conversation

@ericmj
Copy link
Member

@ericmj ericmj commented Sep 10, 2020

No description provided.

@ericmj ericmj requested a review from josevalim September 10, 2020 16:57

assert {:error,
{:unable_unify,
{{:map, [{:required, {:atom, :bar}, :dynamic}, {:optional, :dynamic, :dynamic}]},
Copy link
Member Author

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.

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}]},
Copy link
Member

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.

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)
Copy link
Member

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.

Copy link
Member Author

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>
ericmj and others added 3 commits September 11, 2020 10:44
Co-authored-by: Fernando Tapia Rico <fertapric@gmail.com>
@ericmj ericmj merged commit cc9f4b8 into master Sep 11, 2020
@ericmj ericmj deleted the emj/check-map-update branch September 11, 2020 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants