Skip to content

Commit f685a76

Browse files
authored
Fix another dialyzer Kernel.with edge case (#13869)
Close #13868
1 parent 1f92332 commit f685a76

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

lib/elixir/src/elixir_erl_pass.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ translate_with_else(Meta, [{'else', Else}], S) ->
426426

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

431431
with_else_closure(Meta, TranslatedClauses, S) ->
432432
Ann = ?ann(Meta),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
defmodule Dialyzer.WithThrowingElse do
2+
def with_throwing_else(map) do
3+
with {:ok, foo} <- Map.fetch(map, :foo),
4+
false <- Enum.empty?(foo) do
5+
foo
6+
else
7+
# several clauses but one is a no_return
8+
:error -> throw(:empty_map)
9+
true -> nil
10+
end
11+
end
12+
end

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

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ defmodule Kernel.DialyzerTest do
2626
:elixir,
2727
:elixir_env,
2828
:elixir_erl_pass,
29+
:maps,
2930
ArgumentError,
3031
Atom,
3132
Code,
@@ -164,6 +165,11 @@ defmodule Kernel.DialyzerTest do
164165
assert_dialyze_no_warnings!(context)
165166
end
166167

168+
test "no warnings on with when multiple else clauses and one is a no_return", context do
169+
copy_beam!(context, Dialyzer.WithThrowingElse)
170+
assert_dialyze_no_warnings!(context)
171+
end
172+
167173
test "no warnings on defmacrop", context do
168174
copy_beam!(context, Dialyzer.Defmacrop)
169175
assert_dialyze_no_warnings!(context)

0 commit comments

Comments
 (0)