Skip to content

Commit ec02c65

Browse files
author
José Valim
committed
Fix issue with nested binaries in Macro.to_string/1, closes #1522
1 parent ff0304c commit ec02c65

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/elixir/lib/macro.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ defmodule Macro do
197197

198198
# Bits containers
199199
def to_string({ :<<>>, _, args }) do
200-
"<<" <> Enum.map_join(args, ", ", to_string(&1)) <> ">>"
200+
case Enum.map_join(args, ", ", to_string(&1)) do
201+
"<" <> rest -> "<< <" <> rest <> " >>"
202+
rest -> "<<" <> rest <> ">>"
203+
end
201204
end
202205

203206
# Tuple containers

lib/elixir/test/elixir/macro_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ defmodule MacroTest do
325325
assert Macro.to_string(quote do: { 1, 2, 3 }) == "{1, 2, 3}"
326326
assert Macro.to_string(quote do: [ 1, 2, 3 ]) == "[1, 2, 3]"
327327
assert Macro.to_string(quote do: << 1, 2, 3 >>) == "<<1, 2, 3>>"
328+
assert Macro.to_string(quote do: << <<1>> >>) == "<< <<1>> >>"
328329
end
329330

330331
test :binary_ops_to_string do

0 commit comments

Comments
 (0)