Skip to content

Commit 8be0ad0

Browse files
lexmagJosé Valim
authored andcommitted
Correct Macro.to_string/1 formatting for capture operator
Signed-off-by: José Valim <[email protected]>
1 parent 8da4936 commit 8be0ad0

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

lib/elixir/lib/macro.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,10 @@ defmodule Macro do
571571
fun.(ast, "&" <> to_string(mod, fun) <> "." <> Atom.to_string(name) <> "/" <> to_string(arity, fun))
572572
end
573573

574+
def to_string({:&, _, [arg]} = ast, fun) when not is_integer(arg) do
575+
fun.(ast, "&(" <> to_string(arg, fun) <> ")")
576+
end
577+
574578
# Unary ops
575579
def to_string({unary, _, [{binary, _, [_, _]} = arg]} = ast, fun)
576580
when unary in unquote(@unary_ops) and binary in unquote(@binary_ops) do

lib/elixir/lib/string.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ defmodule String do
88
99
The functions in this module act according to the Unicode
1010
Standard, version 6.3.0.
11-
11+
1212
As per the standard, a codepoint is a single Unicode Character,
1313
which may be represented by one or more bytes.
14-
14+
1515
For example, the codepoint "é" is two bytes:
1616
1717
iex> byte_size("é")

lib/elixir/test/elixir/macro_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ defmodule MacroTest do
387387
assert Macro.to_string(quote do: &foo/0) == "&foo/0"
388388
assert Macro.to_string(quote do: &Foo.foo/0) == "&Foo.foo/0"
389389
assert Macro.to_string(quote do: & &1 + &2) == "&(&1 + &2)"
390+
assert Macro.to_string(quote do: & &1) == "&(&1)"
390391
end
391392

392393
test "containers to string" do
@@ -422,7 +423,6 @@ defmodule MacroTest do
422423
assert Macro.to_string(quote do: !(foo > bar)) == "!(foo > bar)"
423424
assert Macro.to_string(quote do: @foo(bar)) == "@foo(bar)"
424425
assert Macro.to_string(quote do: identity(&1)) == "identity(&1)"
425-
assert Macro.to_string(quote do: identity(&foo)) == "identity(&foo)"
426426
end
427427

428428
test "access to string" do

0 commit comments

Comments
 (0)