Skip to content

Commit 58a6291

Browse files
dazumaJosé Valim
authored and
José Valim
committed
Fix a crash in Macro.to_string if a tree looks like a sigil but the function is not an atom
Signed-off-by: José Valim <[email protected]>
1 parent 8188424 commit 58a6291

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/elixir/lib/macro.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ defmodule Macro do
695695
defp module_to_string(atom, _fun) when is_atom(atom), do: inspect(atom, [])
696696
defp module_to_string(other, fun), do: call_to_string(other, fun)
697697

698-
defp sigil_call({func, _, [{:<<>>, _, _} = bin, args]} = ast, fun) when is_list(args) do
698+
defp sigil_call({func, _, [{:<<>>, _, _} = bin, args]} = ast, fun) when is_atom(func) and is_list(args) do
699699
sigil =
700700
case Atom.to_string(func) do
701701
<<"sigil_", name>> ->

lib/elixir/test/elixir/macro_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ defmodule MacroTest do
290290
assert Macro.to_string(quote do: ~R"123") == ~s/~R"123"/
291291
assert Macro.to_string(quote do: ~R"123"u) == ~s/~R"123"u/
292292
assert Macro.to_string(quote do: ~R"\n123") == ~s/~R"\\\\n123"/
293+
294+
assert Macro.to_string(quote do: Foo.bar(<<>>, [])) == "Foo.bar(<<>>, [])"
293295
end
294296

295297
test "arrow to string" do

0 commit comments

Comments
 (0)