Skip to content

Commit 60b2928

Browse files
author
José Valim
committed
Ensure &() works on blocks with one expressoin, closes #1704
1 parent 3f0c583 commit 60b2928

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/elixir/src/elixir_fn.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ capture(Meta, { { '.', _, [_, Fun] }, _, Args } = Expr, S) when is_atom(Fun), is
4848
capture(Meta, { { '.', _, [_] }, _, Args } = Expr, S) when is_list(Args) ->
4949
do_capture(Meta, Expr, S, false);
5050

51+
capture(Meta, { '__block__', _, [Expr] }, S) ->
52+
capture(Meta, Expr, S);
53+
5154
capture(Meta, { '__block__', _, _ } = Expr, S) ->
5255
Message = "invalid args for &, block expressions are not allowed, got: ~ts",
5356
syntax_error(Meta, S#elixir_scope.file, Message, ['Elixir.Macro':to_string(Expr)]);

lib/elixir/test/elixir/kernel/fn_test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ defmodule Kernel.FnTest do
8383
assert (&(&1.file(&2))).(__ENV__, "Hello").file == "Hello"
8484
end
8585

86+
test "capture block like" do
87+
assert (&(!is_atom(&1))).(:foo) == false
88+
end
89+
8690
test "capture other" do
8791
assert (& &1).(:ok) == :ok
8892

0 commit comments

Comments
 (0)