Skip to content

Commit 9e78534

Browse files
authored
Do not return {:ok, _} on maps with empty lines in map_put_static_value (#15597)
1 parent b8c1eb7 commit 9e78534

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/elixir/lib/module/types/descr.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4004,7 +4004,7 @@ defmodule Module.Types.Descr do
40044004
defp map_put_static_value(descr, split_keys, type) do
40054005
case :maps.take(:dynamic, descr) do
40064006
:error ->
4007-
if descr_key?(descr, :map) and map_only?(descr) do
4007+
if non_empty_map_only?(descr) do
40084008
{:ok, map_put_static(descr, split_keys, type)}
40094009
else
40104010
:badmap

lib/elixir/test/elixir/module/types/descr_test.exs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3677,6 +3677,16 @@ defmodule Module.Types.DescrTest do
36773677
assert map_put(map, atom([:k]), binary()) ==
36783678
{:ok, open_map(k: {binary(), false}, x: {term(), false})}
36793679
end
3680+
3681+
test "is consistent across representations of an empty type" do
3682+
# An empty map component that survives syntactically (open_map(c: none())
3683+
# is a non-normalized empty, equal to none()) must report :badmap like
3684+
# none(), not {:ok, <inhabited>}.
3685+
a2 = open_map(c: {none(), false})
3686+
assert equal?(none(), a2)
3687+
assert map_put(none(), atom([:a]), integer()) == :badmap
3688+
assert map_put(a2, atom([:a]), integer()) == :badmap
3689+
end
36803690
end
36813691

36823692
describe "disjoint" do

0 commit comments

Comments
 (0)