Skip to content

Commit

Permalink
Fix dialyzer error when with else clause is calling a no_return funct…
Browse files Browse the repository at this point in the history
  • Loading branch information
sabiwara committed Jun 13, 2024
1 parent 64e63b1 commit 382362c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/elixir/src/elixir_erl_pass.erl
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ with_else_closure(Meta, TranslatedClauses, S) ->
Ann = ?ann(Meta),
{_, FunErlVar, SC} = elixir_erl_var:assign(Meta, S),
{_, ArgErlVar, SA} = elixir_erl_var:assign(Meta, SC),
FunAssign = {match, Ann, FunErlVar, {'fun', Ann, {clauses, TranslatedClauses}}},
FunCall = {call, Ann, FunErlVar, [ArgErlVar]},
Generated = erl_anno:set_generated(true, Ann),
FunAssign = {match, Ann, FunErlVar, {'fun', Generated, {clauses, TranslatedClauses}}},
FunCall = {call, Ann, FunErlVar, [ArgErlVar]},
{{clause, Generated, [ArgErlVar], [], [FunCall]}, FunAssign, SA}.

translate_with_do([{'<-', Meta, [{Var, _, Ctx} = Left, Expr]} | Rest], Ann, Do, Else, S) when is_atom(Var), is_atom(Ctx) ->
Expand Down
13 changes: 13 additions & 0 deletions lib/elixir/test/elixir/fixtures/dialyzer/with_no_return.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule Dialyzer.WithNoReturn do
def with_no_return(list) do
no_return = fn -> throw(:no_return) end

with [] <- list do
:ok
else
# note: throwing here directly wouldn't be caught in the first place,
# calling a no_return function is what could cause an issue.
_ -> no_return.()
end
end
end
5 changes: 5 additions & 0 deletions lib/elixir/test/elixir/kernel/dialyzer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ defmodule Kernel.DialyzerTest do
assert_dialyze_no_warnings!(context)
end

test "no warnings on with when else has a no_return type", context do
copy_beam!(context, Dialyzer.WithNoReturn)
assert_dialyze_no_warnings!(context)
end

test "no warnings on defmacrop", context do
copy_beam!(context, Dialyzer.Defmacrop)
assert_dialyze_no_warnings!(context)
Expand Down

0 comments on commit 382362c

Please sign in to comment.