Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/elixir/lib/module/types/expr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 5 additions & 5 deletions lib/elixir/test/elixir/module/types/map_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
(
Expand Down
16 changes: 14 additions & 2 deletions lib/elixir/test/elixir/module/types/types_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
(
Expand All @@ -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],
(
Expand All @@ -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