Skip to content

Commit 8e99e3c

Browse files
whatyouhideJosé Valim
authored andcommitted
Bring the "e in _" syntax back to try/rescue (#6360)
1 parent 1515182 commit 8e99e3c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/elixir/src/elixir_clauses.erl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ expand_rescue(Meta, _, E) ->
228228
expand_rescue({Name, _, Atom} = Var, E) when is_atom(Name), is_atom(Atom) ->
229229
match(fun elixir_expand:expand/2, Var, E);
230230

231+
%% rescue var in _ => rescue var
232+
expand_rescue({in, _, [{Name, _, VarContext} = Var, {'_', _, UnderscoreContext}]}, E)
233+
when is_atom(Name), is_atom(VarContext), is_atom(UnderscoreContext) ->
234+
expand_rescue(Var, E);
235+
231236
%% rescue var in [Exprs]
232237
expand_rescue({in, Meta, [Left, Right]}, E) ->
233238
{ELeft, EL} = match(fun elixir_expand:expand/2, Left, E),

lib/elixir/test/elixir/kernel/raise_test.exs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,17 @@ defmodule Kernel.RaiseTest do
229229

230230
assert result
231231
end
232+
233+
test "catch-all with \"x in _\" syntax" do
234+
result = try do
235+
raise "an exception"
236+
rescue
237+
exception in _ ->
238+
Exception.message(exception)
239+
end
240+
241+
assert result == "an exception"
242+
end
232243
end
233244

234245
describe "normalize" do

0 commit comments

Comments
 (0)