Skip to content

Commit 73a9629

Browse files
committed
Fix regression
1 parent 24b319f commit 73a9629

3 files changed

Lines changed: 23 additions & 19 deletions

File tree

lib/elixir/lib/module/types/pattern.ex

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ defmodule Module.Types.Pattern do
556556
root = %{root: {:var, version}, expr: match}
557557

558558
{precise?, static, dynamic, context} =
559-
Enum.reduce(matches, {precise?, [], [], context}, fn
559+
Enum.reduce(matches, {precise?, [], [{:var, version}], context}, fn
560560
pattern, {precise?, static, dynamic, context} ->
561561
{type, pattern_precise?, context} = of_pattern(pattern, [root], stack, context)
562562
precise? = precise? and pattern_precise?
@@ -569,18 +569,14 @@ defmodule Module.Types.Pattern do
569569
end)
570570

571571
return =
572-
cond do
573-
dynamic == [] -> Enum.reduce(static, &intersection/2)
574-
static == [] -> {:intersection, dynamic}
575-
true -> {:intersection, [Enum.reduce(static, &intersection/2) | dynamic]}
572+
if static == [] do
573+
{:intersection, dynamic}
574+
else
575+
{:intersection, [Enum.reduce(static, &intersection/2) | dynamic]}
576576
end
577577

578-
if dynamic == [] do
579-
{return, precise?, context}
580-
else
581-
context = of_var(var, version, [%{root: return, expr: match}], context)
582-
{return, precise?, context}
583-
end
578+
context = of_var(var, version, [%{root: return, expr: match}], context)
579+
{return, precise?, context}
584580
end
585581

586582
# %Struct{...}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,15 @@ defmodule Module.Types.ExprTest do
16731673
tuple([atom([:bitstring]), bitstring_no_binary()])
16741674
)
16751675
)
1676+
1677+
assert typecheck!(
1678+
[condition],
1679+
case condition do
1680+
x = %{} when x != %{} -> :non_empty_map
1681+
%{} -> :maybe_empty_map
1682+
end
1683+
) ==
1684+
atom([:non_empty_map, :maybe_empty_map])
16761685
end
16771686

16781687
test "reports error from redundant clauses" do

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,15 @@ defmodule Module.Types.PatternTest do
129129
"""
130130

131131
assert typeerror!([a = b, a = :foo, b = :bar], {a, b}) == ~l"""
132-
incompatible types assigned to "a":
132+
the following pattern will never match:
133133
134-
dynamic(:foo) !~ dynamic(:bar)
134+
a = b
135135
136-
where "a" was given the types:
137-
138-
# type: dynamic(:foo)
139-
# from: types_test.ex:LINE
140-
a = :foo
136+
where "b" was given the type:
141137
142138
# type: dynamic(:bar)
143139
# from: types_test.ex:LINE
144-
a = b
140+
b = :bar
145141
"""
146142

147143
assert typeerror!([{x, _} = {y, _}, x = :foo, y = :bar], {x, y}) == ~l"""
@@ -910,6 +906,9 @@ defmodule Module.Types.PatternTest do
910906
assert typecheck!([x], x !== [], x) == dynamic(negation(empty_list()))
911907
assert typecheck!([x], not (x != []), x) == dynamic(empty_list())
912908
assert typecheck!([x], not (x !== []), x) == dynamic(empty_list())
909+
910+
assert typecheck!([x], x != %{}, x) == dynamic(negation(empty_map()))
911+
assert typecheck!([x = %{}], x != %{}, x) == dynamic(difference(open_map(), empty_map()))
913912
end
914913

915914
test "with singleton literals and composite types" do

0 commit comments

Comments
 (0)