Skip to content

Commit c46b3cb

Browse files
committed
Fix pop domain
1 parent 98e1502 commit c46b3cb

2 files changed

Lines changed: 73 additions & 30 deletions

File tree

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

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3428,17 +3428,6 @@ defmodule Module.Types.Descr do
34283428
end)
34293429
end
34303430

3431-
defp map_split_negative_pairs_domain(negs, domain_key) do
3432-
Enum.reduce_while(negs, [], fn
3433-
{:open, empty}, _acc when is_fields_empty(empty) ->
3434-
{:halt, :empty}
3435-
3436-
{tag, fields}, neg_acc ->
3437-
{_found?, value, bdd} = map_pop_domain_bdd(tag, fields, domain_key)
3438-
{:cont, [{value, bdd} | neg_acc]}
3439-
end)
3440-
end
3441-
34423431
# Projection shortcuts for the pair-shaped map split below. These are
34433432
# existential checks: if at least one remaining-map sample avoids all negative
34443433
# remaining maps, the full key-value side survives; dually, if at least one
@@ -4275,26 +4264,31 @@ defmodule Module.Types.Descr do
42754264
map_domain_tag_to_type(tag, domain_key) |> union(acc)
42764265

42774266
{tag_or_domains, fields, negs}, acc ->
4278-
{_found, value, bdd} = map_pop_domain_bdd(tag_or_domains, fields, domain_key)
4279-
4280-
case map_split_negative_pairs_domain(negs, domain_key) do
4281-
:empty ->
4282-
acc
4283-
4284-
negative ->
4285-
value =
4286-
if map_pair_projection_keeps_full_fst?(negative, bdd) do
4287-
value
4288-
else
4289-
negs
4290-
|> map_split_negative(value, bdd, fn neg_tag, neg_fields ->
4291-
map_pop_domain_bdd(neg_tag, neg_fields, domain_key)
4292-
end)
4293-
|> Enum.reduce(none(), fn {value, _}, acc -> union(value, acc) end)
4294-
end
4295-
4296-
union(value, acc)
4267+
if init_map_line_empty?(tag_or_domains, fields, negs) do
4268+
acc
4269+
else
4270+
{_found, value, _bdd} = map_pop_domain_bdd(tag_or_domains, fields, domain_key)
4271+
union(value, acc)
42974272
end
4273+
4274+
# case map_split_negative_pairs_domain(negs, domain_key) do
4275+
# :empty ->
4276+
# acc
4277+
4278+
# negative ->
4279+
# value =
4280+
# if map_pair_projection_keeps_full_fst?(negative, bdd) do
4281+
# value
4282+
# else
4283+
# negs
4284+
# |> map_split_negative(value, bdd, fn neg_tag, neg_fields ->
4285+
# map_pop_domain_bdd(neg_tag, neg_fields, domain_key)
4286+
# end)
4287+
# |> Enum.reduce(none(), fn {value, _}, acc -> union(value, acc) end)
4288+
# end
4289+
4290+
# union(value, acc)
4291+
# end
42984292
end)
42994293
end
43004294

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,6 +2241,55 @@ defmodule Module.Types.DescrTest do
22412241
map = closed_map([{:a, atom([:a])}, {:__struct__, term()}, {domain_key(:atom), pid()}])
22422242
{:ok, term} = map_get(map, atom() |> difference(atom([:a])))
22432243
assert equal?(term, term())
2244+
2245+
base = open_map([{domain_key(:atom), term()}])
2246+
bad = open_map(a: if_set(negation(integer())))
2247+
map = negation(union(negation(base), bad))
2248+
2249+
assert equal?(map, open_map(a: integer()))
2250+
2251+
{:ok, type} = map_get(map, atom())
2252+
assert equal?(type, term())
2253+
2254+
{:ok, type} = map_get(map, atom([:a]))
2255+
assert equal?(type, integer())
2256+
2257+
map = closed_map([{:a, term()}, {domain_key(:atom), integer()}])
2258+
2259+
{:ok, type} = map_get(map, atom())
2260+
assert equal?(type, term())
2261+
2262+
{:ok, type} = map_get(map, atom([:a]))
2263+
assert equal?(type, term())
2264+
2265+
{:ok, type} = map_get(map, difference(atom(), atom([:a])))
2266+
assert equal?(type, integer())
2267+
2268+
map =
2269+
closed_map([{:a, term()}, {domain_key(:atom), integer()}])
2270+
|> difference(open_map(a: negation(pid())))
2271+
2272+
{:ok, type} = map_get(map, atom())
2273+
assert equal?(type, union(integer(), pid()))
2274+
2275+
{:ok, type} = map_get(map, atom([:a]))
2276+
assert equal?(type, pid())
2277+
2278+
{:ok, type} = map_get(map, difference(atom(), atom([:a])))
2279+
assert equal?(type, integer())
2280+
2281+
map =
2282+
closed_map([{:a, term()}, {:b, binary()}, {domain_key(:atom), integer()}])
2283+
|> difference(open_map(a: negation(pid())))
2284+
2285+
{:ok, type} = map_get(map, atom())
2286+
assert equal?(type, union(union(integer(), pid()), binary()))
2287+
2288+
{:ok, type} = map_get(map, atom([:a, :b]))
2289+
assert equal?(type, union(pid(), binary()))
2290+
2291+
{:ok, type} = map_get(map, difference(atom(), atom([:a, :b])))
2292+
assert equal?(type, integer())
22442293
end
22452294

22462295
test "with lists" do

0 commit comments

Comments
 (0)