Skip to content

Commit 1ae3e34

Browse files
author
Daniel Perez
committed
Fix bug in Macro.to_string. Fix #4116.
1 parent 94c9f39 commit 1ae3e34

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/elixir/lib/macro.ex

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,11 @@ defmodule Macro do
483483
fun.(ast, interpolate(ast, fun))
484484
else
485485
result = Enum.map_join(parts, ", ", fn(part) ->
486-
case bitpart_to_string(part, fun) do
487-
"<" <> rest ->
488-
"(<" <> rest <> ")"
489-
other -> other
486+
str = bitpart_to_string(part, fun)
487+
if String.first(str) == "<" or String.last(str) == ">" do
488+
"(" <> str <> ")"
489+
else
490+
str
490491
end
491492
end)
492493
fun.(ast, "<<" <> result <> ">>")

lib/elixir/test/elixir/macro_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ defmodule MacroTest do
449449
assert Macro.to_string(ast) == "<<(<<65>>), 65>>"
450450
ast = quote(do: <<65, <<65>> >>)
451451
assert Macro.to_string(ast) == "<<65, (<<65>>)>>"
452+
ast = quote do: for <<a::4 <- <<1, 2>> >>, do: a
453+
assert Macro.to_string(ast) == "for(<<(a :: 4 <- <<1, 2>>)>>) do\n a\nend"
452454
end
453455

454456
test "charlist to string" do

0 commit comments

Comments
 (0)