@@ -46,8 +46,8 @@ defmodule Module.Types.Descr do
4646 @ not_non_empty_list Map . delete ( @ term , :list )
4747 @ not_list Map . replace! ( @ not_non_empty_list , :bitmap , @ bit_top - @ bit_empty_list )
4848
49- @ empty_intersection [ 0 , @ none , [ ] , :fun_bottom ]
50- @ empty_difference [ 0 , [ ] , :fun_bottom ]
49+ @ empty_intersection [ 0 , [ ] ]
50+ @ empty_difference [ 0 , [ ] ]
5151
5252 defguard is_descr ( descr ) when is_map ( descr ) or descr == :term
5353
@@ -398,12 +398,20 @@ defmodule Module.Types.Descr do
398398 # Returning 0 from the callback is taken as none() for that subtype.
399399 defp intersection ( :atom , v1 , v2 ) , do: atom_intersection ( v1 , v2 )
400400 defp intersection ( :bitmap , v1 , v2 ) , do: v1 &&& v2
401- defp intersection ( :dynamic , v1 , v2 ) , do: dynamic_intersection ( v1 , v2 )
402401 defp intersection ( :list , v1 , v2 ) , do: list_intersection ( v1 , v2 )
403402 defp intersection ( :map , v1 , v2 ) , do: map_intersection ( v1 , v2 )
404403 defp intersection ( :optional , 1 , 1 ) , do: 1
405404 defp intersection ( :tuple , v1 , v2 ) , do: tuple_intersection ( v1 , v2 )
406- defp intersection ( :fun , v1 , v2 ) , do: fun_intersection ( v1 , v2 )
405+
406+ defp intersection ( :fun , v1 , v2 ) do
407+ bdd = fun_intersection ( v1 , v2 )
408+ if bdd == :fun_bottom , do: 0 , else: bdd
409+ end
410+
411+ defp intersection ( :dynamic , v1 , v2 ) do
412+ descr = dynamic_intersection ( v1 , v2 )
413+ if descr == @ none , do: 0 , else: descr
414+ end
407415
408416 @ doc """
409417 Computes the difference between two types.
@@ -490,7 +498,11 @@ defmodule Module.Types.Descr do
490498 defp difference ( :map , v1 , v2 ) , do: map_difference ( v1 , v2 )
491499 defp difference ( :optional , 1 , 1 ) , do: 0
492500 defp difference ( :tuple , v1 , v2 ) , do: tuple_difference ( v1 , v2 )
493- defp difference ( :fun , v1 , v2 ) , do: fun_difference ( v1 , v2 )
501+
502+ defp difference ( :fun , v1 , v2 ) do
503+ bdd = fun_difference ( v1 , v2 )
504+ if bdd == :fun_bottom , do: 0 , else: bdd
505+ end
494506
495507 @ doc """
496508 Compute the negation of a type.
@@ -2391,10 +2403,6 @@ defmodule Module.Types.Descr do
23912403 :empty -> acc
23922404 end
23932405 end
2394- |> case do
2395- [ ] -> 0
2396- acc -> acc
2397- end
23982406 end
23992407
24002408 # Intersects two map literals; throws if their intersection is empty.
0 commit comments