Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jan 2, 2025
1 parent d961fef commit 63283d5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/elixir/lib/module/types/expr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ defmodule Module.Types.Expr do
{timeout_type, context} = of_expr(timeout, {@timeout_type, after_expr}, stack, context)
{body_type, context} = of_expr(body, expected_expr, stack, context)

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

# We use subtype? instead of compatible because we want to handle
# only binary/list, even if a dynamic with something else is given.
if subtype?(type, @into_compile) do
case {binary_type?(type), empty_list_type?(type)} do
{false, true} -> {[:list], gradual?(type), context}
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/lib/module/types/pattern.ex
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ defmodule Module.Types.Pattern do

case of_pattern_var(path, actual, true, info, context) do
{type, reachable_var?} ->
# If current type is already a subtype, there is nothing to refine.
# Optimization: if current type is already a subtype, there is nothing to refine.
with %{^version => %{type: current_type}} <- context.vars,
true <- subtype?(current_type, type) do
{var_changed?, context}
Expand Down
10 changes: 10 additions & 0 deletions lib/elixir/test/elixir/module/types/expr_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,16 @@ defmodule Module.Types.ExprTest do
) == dynamic(atom([:ok, :error, :timeout]))
end

test "infers type for timeout" do
assert typecheck!(
[x],
receive do
after
x -> x
end
) == dynamic(union(integer(), atom([:infinity])))
end

test "resets branches" do
assert typecheck!(
[x, timeout = :infinity],
Expand Down

0 comments on commit 63283d5

Please sign in to comment.