Skip to content

Fix another dialyzer Kernel.with edge case #13869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/elixir/src/elixir_erl_pass.erl
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ translate_with_else(Meta, [{'else', Else}], S) ->

Clauses = elixir_erl_clauses:get_clauses('else', [{'else', Else ++ [RaiseClause]}], match),
{TranslatedClauses, SC} = elixir_erl_clauses:clauses(Clauses, SV#elixir_erl{extra=pin_guard}),
with_else_closure(Meta, TranslatedClauses, SC#elixir_erl{extra=SV#elixir_erl.extra}).
with_else_closure(Generated, TranslatedClauses, SC#elixir_erl{extra=SV#elixir_erl.extra}).

with_else_closure(Meta, TranslatedClauses, S) ->
Ann = ?ann(Meta),
Expand Down
12 changes: 12 additions & 0 deletions lib/elixir/test/elixir/fixtures/dialyzer/with_throwing_else.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule Dialyzer.WithThrowingElse do
def with_throwing_else(map) do
with {:ok, foo} <- Map.fetch(map, :foo),
false <- Enum.empty?(foo) do
foo
else
# several clauses but one is a no_return
:error -> throw(:empty_map)
true -> nil
end
end
end
6 changes: 6 additions & 0 deletions lib/elixir/test/elixir/kernel/dialyzer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ defmodule Kernel.DialyzerTest do
:elixir,
:elixir_env,
:elixir_erl_pass,
:maps,
ArgumentError,
Atom,
Code,
Expand Down Expand Up @@ -164,6 +165,11 @@ defmodule Kernel.DialyzerTest do
assert_dialyze_no_warnings!(context)
end

test "no warnings on with when multiple else clauses and one is a no_return", context do
copy_beam!(context, Dialyzer.WithThrowingElse)
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
Loading