diff --git a/lib/elixir/lib/module/types/expr.ex b/lib/elixir/lib/module/types/expr.ex index 02363cb0042..1fb7ea3651a 100644 --- a/lib/elixir/lib/module/types/expr.ex +++ b/lib/elixir/lib/module/types/expr.ex @@ -151,7 +151,7 @@ defmodule Module.Types.Expr do dynamic_value_pairs = 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 + {:ok, type, context} <- unify(map_type, args_type, stack, context) do # Retrieve map type and overwrite with the new value types from the map update {:map, pairs} = resolve_var(type, context) diff --git a/lib/elixir/test/elixir/module/types/map_test.exs b/lib/elixir/test/elixir/module/types/map_test.exs index 5324c845399..da6818f2e54 100644 --- a/lib/elixir/test/elixir/module/types/map_test.exs +++ b/lib/elixir/test/elixir/module/types/map_test.exs @@ -201,8 +201,8 @@ defmodule Module.Types.MapTest do assert {:error, {:unable_unify, - {{:map, [{:required, {:atom, :bar}, :dynamic}, {:optional, :dynamic, :dynamic}]}, - {:map, [{:required, {:atom, :foo}, {:atom, :a}}]}, + {{:map, [{:required, {:atom, :foo}, {:atom, :a}}]}, + {:map, [{:required, {:atom, :bar}, :dynamic}, {:optional, :dynamic, :dynamic}]}, _}}} = quoted_expr( ( @@ -231,8 +231,8 @@ defmodule Module.Types.MapTest do {:unable_unify, {{:map, [ - {:required, {:atom, :field}, {:atom, :b}}, {:required, {:atom, :foo}, {:var, 1}}, + {:required, {:atom, :field}, {:atom, :b}}, {:optional, :dynamic, :dynamic} ]}, {:map, @@ -276,12 +276,12 @@ defmodule Module.Types.MapTest do assert {:error, {:unable_unify, {{:map, - [{:required, {:atom, :not_field}, :dynamic}, {:optional, :dynamic, :dynamic}]}, - {:map, [ {:required, {:atom, :field}, {:atom, nil}}, {:required, {:atom, :__struct__}, {:atom, Module.Types.MapTest.Struct2}} ]}, + {:map, + [{:required, {:atom, :not_field}, :dynamic}, {:optional, :dynamic, :dynamic}]}, _}}} = quoted_expr( ( diff --git a/lib/elixir/test/elixir/module/types/types_test.exs b/lib/elixir/test/elixir/module/types/types_test.exs index 383a5880dd8..fcec53f2267 100644 --- a/lib/elixir/test/elixir/module/types/types_test.exs +++ b/lib/elixir/test/elixir/module/types/types_test.exs @@ -706,7 +706,7 @@ defmodule Module.Types.TypesTest do ) == :none end - test "other recursive" do + test "map patterns with pinned keys and field access" do assert warning( [x, y], ( @@ -719,7 +719,7 @@ defmodule Module.Types.TypesTest do ) == :none end - test "other recursive2" do + test "map patterns with pinned keys" do assert warning( [x, y], ( @@ -732,5 +732,17 @@ defmodule Module.Types.TypesTest do ) ) == :none end + + test "map updates with var key" do + assert warning( + [state0, key0], + ( + state1 = %{state0 | key0 => true} + key1 = key0 + state2 = %{state1 | key1 => true} + state2 + ) + ) == :none + end end end