Skip to content

Commit 662e5f1

Browse files
committed
More
1 parent 3e0728c commit 662e5f1

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,12 +1613,20 @@ defmodule Module.Types.Descr do
16131613

16141614
defp fun_difference(bdd1, bdd2), do: bdd_difference(bdd1, bdd2)
16151615

1616-
defp fun_top?(bdd, {{args, return}, :bdd_top, :bdd_bot, :bdd_bot}) do
1617-
return == :term and Enum.all?(args, &(&1 == %{})) and
1618-
matching_arity_left?(bdd, length(args))
1616+
defp fun_top?(bdd, other_bdd) do
1617+
case bdd_expand(other_bdd) do
1618+
{{args, return}, :bdd_top, :bdd_bot, :bdd_bot} ->
1619+
return == :term and Enum.all?(args, &(&1 == %{})) and
1620+
matching_arity_left?(bdd, length(args))
1621+
1622+
_ ->
1623+
false
1624+
end
16191625
end
16201626

1621-
defp fun_top?(_, _), do: false
1627+
defp matching_arity_left?({args, _return}, arity) do
1628+
length(args) == arity
1629+
end
16221630

16231631
defp matching_arity_left?({{args, _return}, l, u, r}, arity) do
16241632
length(args) == arity and matching_arity_left?(l, arity) and matching_arity_left?(u, arity) and
@@ -1912,8 +1920,8 @@ defmodule Module.Types.Descr do
19121920
@compile {:inline, list_union: 2}
19131921
defp list_union(bdd1, bdd2), do: bdd_union(bdd1, bdd2)
19141922

1915-
defp is_list_top?(bdd_leaf(list, tail)), do: list == :term and tail == :term
1916-
defp is_list_top?(_), do: false
1923+
defp list_top?(bdd_leaf(:term, :term)), do: true
1924+
defp list_top?(_), do: false
19171925

19181926
defp list_intersection(bdd_leaf(list1, last1), bdd_leaf(list2, last2)) do
19191927
try do
@@ -1927,8 +1935,8 @@ defmodule Module.Types.Descr do
19271935

19281936
defp list_intersection(bdd1, bdd2) do
19291937
cond do
1930-
is_list_top?(bdd1) and is_tuple(bdd2) -> bdd2
1931-
is_list_top?(bdd2) and is_tuple(bdd1) -> bdd1
1938+
list_top?(bdd1) and is_tuple(bdd2) -> bdd2
1939+
list_top?(bdd2) and is_tuple(bdd1) -> bdd1
19321940
true -> bdd_intersection(bdd1, bdd2)
19331941
end
19341942
end
@@ -2494,8 +2502,8 @@ defmodule Module.Types.Descr do
24942502
if subtype?(v2, v1), do: :right_subtype_of_left
24952503
end
24962504

2497-
defp is_map_top?(bdd_leaf(:open, fields)) when map_size(fields) == 0, do: true
2498-
defp is_map_top?(_), do: false
2505+
defp map_top?(bdd_leaf(:open, fields)) when map_size(fields) == 0, do: true
2506+
defp map_top?(_), do: false
24992507

25002508
defp map_intersection(bdd_leaf(tag1, fields1), bdd_leaf(tag2, fields2)) do
25012509
try do
@@ -2509,8 +2517,8 @@ defmodule Module.Types.Descr do
25092517
defp map_intersection(bdd1, bdd2) do
25102518
# If intersecting with the top map type, no-op
25112519
cond do
2512-
is_map_top?(bdd1) and is_tuple(bdd2) -> bdd2
2513-
is_map_top?(bdd2) and is_tuple(bdd1) -> bdd1
2520+
map_top?(bdd1) and is_tuple(bdd2) -> bdd2
2521+
map_top?(bdd2) and is_tuple(bdd1) -> bdd1
25142522
true -> bdd_intersection(bdd1, bdd2)
25152523
end
25162524
end

0 commit comments

Comments
 (0)