Skip to content

Commit 3caa8ba

Browse files
committed
Unify :empty_list and :list domains in maps
1 parent 7da1b76 commit 3caa8ba

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ defmodule Module.Types.Descr do
3232

3333
@domain_key_types [
3434
{:domain_key, :binary},
35-
{:domain_key, :empty_list},
3635
{:domain_key, :integer},
3736
{:domain_key, :float},
3837
{:domain_key, :pid},
@@ -3031,7 +3030,7 @@ defmodule Module.Types.Descr do
30313030
defp bitmap_to_domain_keys(bitmap) do
30323031
[
30333032
if((bitmap &&& @bit_binary) != 0, do: domain_key(:binary)),
3034-
if((bitmap &&& @bit_empty_list) != 0, do: domain_key(:empty_list)),
3033+
if((bitmap &&& @bit_empty_list) != 0, do: domain_key(:list)),
30353034
if((bitmap &&& @bit_integer) != 0, do: domain_key(:integer)),
30363035
if((bitmap &&& @bit_float) != 0, do: domain_key(:float)),
30373036
if((bitmap &&& @bit_pid) != 0, do: domain_key(:pid)),

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,18 @@ defmodule Module.Types.DescrTest do
17021702
t2 = closed_map([{domain_key(:tuple), float()}])
17031703
t3 = union(t1, t2)
17041704
assert map_get(t3, tuple()) == {:ok, number() |> nil_or_type()}
1705+
1706+
# Verify that empty_list() bitmap type maps to :list domain (not :empty_list domain)
1707+
map_with_list_domain = closed_map([{domain_key(:list), atom([:empty])}])
1708+
1709+
# empty_list() should access the :list domain
1710+
assert map_get(map_with_list_domain, empty_list()) == {:ok, atom([:empty]) |> nil_or_type()}
1711+
1712+
# non_empty_list() should also access the :list domain
1713+
assert map_get(map_with_list_domain, non_empty_list(integer())) == {:ok, atom([:empty]) |> nil_or_type()}
1714+
1715+
# list() should also access the :list domain
1716+
assert map_get(map_with_list_domain, list(integer())) == {:ok, atom([:empty]) |> nil_or_type()}
17051717
end
17061718

17071719
test "map_get with dynamic" do

0 commit comments

Comments
 (0)