Skip to content

Commit d25845c

Browse files
authored
Fix dialyzer error when with else clause is calling a no_return function (#13659)
Close #13656
1 parent 5945fb6 commit d25845c

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

lib/elixir/src/elixir_erl_pass.erl

+2-2
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,9 @@ with_else_closure(Meta, TranslatedClauses, S) ->
432432
Ann = ?ann(Meta),
433433
{_, FunErlVar, SC} = elixir_erl_var:assign(Meta, S),
434434
{_, ArgErlVar, SA} = elixir_erl_var:assign(Meta, SC),
435-
FunAssign = {match, Ann, FunErlVar, {'fun', Ann, {clauses, TranslatedClauses}}},
436-
FunCall = {call, Ann, FunErlVar, [ArgErlVar]},
437435
Generated = erl_anno:set_generated(true, Ann),
436+
FunAssign = {match, Ann, FunErlVar, {'fun', Generated, {clauses, TranslatedClauses}}},
437+
FunCall = {call, Ann, FunErlVar, [ArgErlVar]},
438438
{{clause, Generated, [ArgErlVar], [], [FunCall]}, FunAssign, SA}.
439439

440440
translate_with_do([{'<-', Meta, [{Var, _, Ctx} = Left, Expr]} | Rest], Ann, Do, Else, S) when is_atom(Var), is_atom(Ctx) ->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
defmodule Dialyzer.WithNoReturn do
2+
def with_no_return(list) do
3+
no_return = fn -> throw(:no_return) end
4+
5+
with [] <- list do
6+
:ok
7+
else
8+
# note: throwing here directly wouldn't be caught in the first place,
9+
# calling a no_return function is what could cause an issue.
10+
_ -> no_return.()
11+
end
12+
end
13+
end

lib/elixir/test/elixir/kernel/dialyzer_test.exs

+5
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ defmodule Kernel.DialyzerTest do
159159
assert_dialyze_no_warnings!(context)
160160
end
161161

162+
test "no warnings on with when else has a no_return type", context do
163+
copy_beam!(context, Dialyzer.WithNoReturn)
164+
assert_dialyze_no_warnings!(context)
165+
end
166+
162167
test "no warnings on defmacrop", context do
163168
copy_beam!(context, Dialyzer.Defmacrop)
164169
assert_dialyze_no_warnings!(context)

0 commit comments

Comments
 (0)