Skip to content

Commit 63283d5

Browse files
committed
More tests
1 parent d961fef commit 63283d5

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ defmodule Module.Types.Expr do
360360
{timeout_type, context} = of_expr(timeout, {@timeout_type, after_expr}, stack, context)
361361
{body_type, context} = of_expr(body, expected_expr, stack, context)
362362

363-
if compatible?(timeout_type, @timeout_type) do
363+
if integer_type?(timeout_type) or atom_type?(timeout_type, :infinity) do
364364
{union(body_type, acc), reset_vars(context, original)}
365365
else
366366
error = {:badtimeout, timeout_type, timeout, context}
@@ -620,6 +620,8 @@ defmodule Module.Types.Expr do
620620
defp for_into(into, meta, stack, context) do
621621
{type, context} = of_expr(into, @expected_expr, stack, context)
622622

623+
# We use subtype? instead of compatible because we want to handle
624+
# only binary/list, even if a dynamic with something else is given.
623625
if subtype?(type, @into_compile) do
624626
case {binary_type?(type), empty_list_type?(type)} do
625627
{false, true} -> {[:list], gradual?(type), context}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ defmodule Module.Types.Pattern do
177177

178178
case of_pattern_var(path, actual, true, info, context) do
179179
{type, reachable_var?} ->
180-
# If current type is already a subtype, there is nothing to refine.
180+
# Optimization: if current type is already a subtype, there is nothing to refine.
181181
with %{^version => %{type: current_type}} <- context.vars,
182182
true <- subtype?(current_type, type) do
183183
{var_changed?, context}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,16 @@ defmodule Module.Types.ExprTest do
12311231
) == dynamic(atom([:ok, :error, :timeout]))
12321232
end
12331233

1234+
test "infers type for timeout" do
1235+
assert typecheck!(
1236+
[x],
1237+
receive do
1238+
after
1239+
x -> x
1240+
end
1241+
) == dynamic(union(integer(), atom([:infinity])))
1242+
end
1243+
12341244
test "resets branches" do
12351245
assert typecheck!(
12361246
[x, timeout = :infinity],

0 commit comments

Comments
 (0)