@@ -2750,8 +2750,8 @@ defmodule Module.Types.Descr do
27502750 else
27512751 # Case 2: the maps have all but one key in common. Do the difference of that key.
27522752 case map_all_but_one ( tag , fields , neg_tag , neg_fields ) do
2753- { :one , diff_key } ->
2754- bdd_leaf ( tag , Map . update !( fields , diff_key , & difference ( & 1 , neg_fields [ diff_key ] ) ) )
2753+ { diff_key , type1 , type2 } ->
2754+ bdd_leaf ( tag , Map . replace !( fields , diff_key , difference ( type1 , type2 ) ) )
27552755
27562756 _ ->
27572757 bdd_difference ( map1 , map2 , & map_leaf_intersection / 2 , nil )
@@ -3972,8 +3972,8 @@ defmodule Module.Types.Descr do
39723972 { acc_fields , acc_negs }
39733973 else
39743974 case map_all_but_one ( tag , acc_fields , neg_tag , neg_fields ) do
3975- { :one , diff_key } ->
3976- { Map . update !( acc_fields , diff_key , & difference ( & 1 , neg_fields [ diff_key ] ) ) , acc_negs }
3975+ { diff_key , type1 , type2 } ->
3976+ { Map . replace !( acc_fields , diff_key , difference ( type1 , type2 ) ) , acc_negs }
39773977
39783978 _ ->
39793979 { acc_fields , [ neg | acc_negs ] }
@@ -4019,20 +4019,29 @@ defmodule Module.Types.Descr do
40194019 defp map_all_but_one ( tag1 , fields1 , tag2 , fields2 ) do
40204020 with true <- { tag1 , tag2 } != { :open , :closed } ,
40214021 true <- map_size ( fields1 ) == map_size ( fields2 ) ,
4022- keys = :maps . keys ( fields1 ) ,
4023- true <- Enum . all? ( keys , fn key -> is_map_key ( fields2 , key ) end ) ,
4024- 1 <-
4025- Enum . count_until (
4026- keys ,
4027- fn key -> Map . fetch! ( fields1 , key ) != Map . fetch! ( fields2 , key ) end ,
4028- _limit = 2
4029- ) do
4030- { :one , Enum . find ( keys , & ( Map . fetch! ( fields1 , & 1 ) != Map . fetch! ( fields2 , & 1 ) ) ) }
4022+ [ triplet ] <- map_all_but_one_find ( :maps . keys ( fields1 ) , fields1 , fields2 , [ ] ) do
4023+ triplet
40314024 else
4032- _ -> :no
4025+ _ -> :error
40334026 end
40344027 end
40354028
4029+ defp map_all_but_one_find ( [ key | keys ] , fields1 , fields2 , found ) do
4030+ case { fields1 , fields2 } do
4031+ { % { ^ key => type1 } , % { ^ key => type2 } } ->
4032+ cond do
4033+ type1 == type2 -> map_all_but_one_find ( keys , fields1 , fields2 , found )
4034+ found == [ ] -> map_all_but_one_find ( keys , fields1 , fields2 , [ { key , type1 , type2 } ] )
4035+ true -> [ ]
4036+ end
4037+
4038+ { _ , _ } ->
4039+ [ ]
4040+ end
4041+ end
4042+
4043+ defp map_all_but_one_find ( [ ] , _fields1 , _fields2 , found ) , do: found
4044+
40364045 defp map_to_quoted ( bdd , opts ) do
40374046 bdd
40384047 |> map_bdd_to_dnf ( )
0 commit comments