Skip to content

Commit 0eabf48

Browse files
committed
Refine types from case on inference
1 parent b0db1a2 commit 0eabf48

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

lib/elixir/lib/module/types/expr.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ defmodule Module.Types.Expr do
487487
end)
488488

489489
context =
490-
if none? do
490+
if none? or stack.mode != :static do
491491
head_type = Enum.reduce(clauses_acc, none(), &union(elem(&1, 0), &2))
492492

493493
{_, refined_context} =

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1919,7 +1919,7 @@ defmodule Module.Types.ExprTest do
19191919
) == dynamic()
19201920
end
19211921

1922-
test "refine types when there are branches (case)" do
1922+
test "refine types when there are dead branches (case)" do
19231923
assert typecheck!(
19241924
[x, key],
19251925
(
@@ -1958,6 +1958,32 @@ defmodule Module.Types.ExprTest do
19581958
) == dynamic(open_map())
19591959
end
19601960

1961+
test "refine types when it is dynamic" do
1962+
assert typecheck!(
1963+
[x],
1964+
(
1965+
case x do
1966+
{} -> :tuple
1967+
%{} -> :empty_list
1968+
end
1969+
1970+
x
1971+
)
1972+
) == dynamic()
1973+
1974+
assert typedyn(
1975+
[x],
1976+
(
1977+
case x do
1978+
{} -> :tuple
1979+
%{} -> :empty_list
1980+
end
1981+
1982+
x
1983+
)
1984+
) == dynamic(union(open_map(), tuple([])))
1985+
end
1986+
19611987
test "warns on redundant clauses" do
19621988
assert typewarn!(
19631989
[x],

0 commit comments

Comments
 (0)