Skip to content

Commit 906f031

Browse files
oneemanJosé Valim
authored andcommitted
Return value when matching with _ on last line of block
Closes #3125 Signed-off-by: José Valim <[email protected]>
1 parent 6a594e2 commit 906f031

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/elixir/src/elixir_translator.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
translate({'=', Meta, [Left, Right]}, S) ->
1212
Return = case Left of
13-
{'_', _, Atom} when is_atom(Atom) -> false;
13+
{'_', _, Atom} when is_atom(Atom) -> S#elixir_scope.return;
1414
_ -> true
1515
end,
1616

lib/elixir/test/elixir/kernel/comprehension_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ defmodule Kernel.ComprehensionTest do
151151
assert for({_,x} <- [1, 2, a: 3, b: 4, c: 5], do: x * 2) == [6, 8, 10]
152152
end
153153

154+
test "list for comprehension matched to '_' on last line of block" do
155+
assert (if true do
156+
_ = for x <- [1, 2, 3], do: x * 2
157+
end) == [2, 4, 6]
158+
end
159+
154160
test "list for comprehensions with filters" do
155161
assert for(x <- [1, 2, 3], x > 1, x < 3, do: x * 2) == [4]
156162
end

0 commit comments

Comments
 (0)