@@ -915,14 +915,9 @@ defmodule Module.Types.Descr do
915
915
true
916
916
917
917
# The key is not shared between positive and negative maps,
918
- # and because the negative type is required, there is no value in common
919
- tag == :closed and not is_optional_static ( neg_type ) ->
920
- false
921
-
922
- # The key is not shared between positive and negative maps,
923
- # but because the negative type is not required, there may be a value in common
918
+ # if the negative type is optional, then there may be a value in common
924
919
tag == :closed ->
925
- true
920
+ is_optional_static ( neg_type )
926
921
927
922
# There may be value in common
928
923
tag == :open ->
@@ -937,12 +932,17 @@ defmodule Module.Types.Descr do
937
932
empty? ( diff ) or map_empty? ( tag , Map . put ( fields , key , diff ) , negs )
938
933
939
934
% { } ->
940
- if neg_tag == :closed and not is_optional_static ( type ) do
941
- false
942
- else
943
- # an absent key in a open negative map can be ignored
944
- diff = difference ( type , tag_to_type ( neg_tag ) )
945
- empty? ( diff ) or map_empty? ( tag , Map . put ( fields , key , diff ) , negs )
935
+ cond do
936
+ neg_tag == :open ->
937
+ true
938
+
939
+ neg_tag == :closed and not is_optional_static ( type ) ->
940
+ false
941
+
942
+ true ->
943
+ # an absent key in a open negative map can be ignored
944
+ diff = difference ( type , tag_to_type ( neg_tag ) )
945
+ empty? ( diff ) or map_empty? ( tag , Map . put ( fields , key , diff ) , negs )
946
946
end
947
947
end
948
948
end ) ) or map_empty? ( tag , fields , negs )
@@ -1412,24 +1412,20 @@ defmodule Module.Types.Descr do
1412
1412
# are disjoint on their first component.
1413
1413
defp pair_eliminate_negations ( negative , t , s ) do
1414
1414
{ pair_union , diff_of_t_i } =
1415
- Enum . reduce (
1416
- negative ,
1417
- { [ ] , t } ,
1418
- fn { t_i , s_i } , { accu , diff_of_t_i } ->
1419
- i = intersection ( t , t_i )
1420
-
1421
- if empty? ( i ) do
1422
- { accu , diff_of_t_i }
1423
- else
1424
- diff_of_t_i = difference ( diff_of_t_i , t_i )
1425
- s_diff = difference ( s , s_i )
1415
+ Enum . reduce ( negative , { [ ] , t } , fn { t_i , s_i } , { accu , diff_of_t_i } ->
1416
+ i = intersection ( t , t_i )
1426
1417
1427
- if empty? ( s_diff ) ,
1428
- do: { accu , diff_of_t_i } ,
1429
- else: { [ i | accu ] , diff_of_t_i }
1430
- end
1418
+ if empty? ( i ) do
1419
+ { accu , diff_of_t_i }
1420
+ else
1421
+ diff_of_t_i = difference ( diff_of_t_i , t_i )
1422
+ s_diff = difference ( s , s_i )
1423
+
1424
+ if empty? ( s_diff ) ,
1425
+ do: { accu , diff_of_t_i } ,
1426
+ else: { [ i | accu ] , diff_of_t_i }
1431
1427
end
1432
- )
1428
+ end )
1433
1429
1434
1430
[ diff_of_t_i | pair_union ]
1435
1431
end
0 commit comments