diff --git a/lib/elixir/lib/macro.ex b/lib/elixir/lib/macro.ex index cc60004e65..0814a7cd2c 100644 --- a/lib/elixir/lib/macro.ex +++ b/lib/elixir/lib/macro.ex @@ -1022,11 +1022,13 @@ defmodule Macro do binary when is_binary(binary) -> binary = inspect_no_limit(binary) - binary_part(binary, 1, byte_size(binary) - 2) + + binary + |> binary_part(1, byte_size(binary) - 2) + |> escape_sigil(left) end) - escaped = escape_sigil(parts, left) - <> + <> end defp escape_sigil(parts, "("), do: String.replace(parts, ")", ~S"\)") diff --git a/lib/elixir/test/elixir/macro_test.exs b/lib/elixir/test/elixir/macro_test.exs index 667051dfa3..d349a993d1 100644 --- a/lib/elixir/test/elixir/macro_test.exs +++ b/lib/elixir/test/elixir/macro_test.exs @@ -344,6 +344,7 @@ defmodule MacroTest do assert Macro.to_string(quote(do: ~R"\n123")) == ~S/~R"\n123"/ assert Macro.to_string(quote(do: ~S["'(123)'"])) == ~S/~S["'(123)'"]/ + assert Macro.to_string(quote(do: ~s"#{"foo"}")) == ~S/~s"#{"foo"}"/ assert Macro.to_string( quote do @@ -704,6 +705,12 @@ defmodule MacroTest do assert Macro.to_string(quote(do: 'abc')) == "'abc'" end + test "string" do + assert Macro.to_string(quote(do: "")) == ~S/""/ + assert Macro.to_string(quote(do: "abc")) == ~S/"abc"/ + assert Macro.to_string(quote(do: "#{"abc"}")) == ~S/"#{"abc"}"/ + end + test "last arg keyword list" do assert Macro.to_string(quote(do: foo([]))) == "foo([])" assert Macro.to_string(quote(do: foo(x: y))) == "foo(x: y)"