Skip to content

Commit 58455c1

Browse files
committed
Do not raise on variable looking like an empty tuple
1 parent d4a2dfc commit 58455c1

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

lib/elixir/lib/code/normalizer.ex

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,17 @@ defmodule Code.Normalizer do
6363
end
6464

6565
# Bit containers
66-
defp do_normalize({:<<>>, _, _} = quoted, state) do
66+
defp do_normalize({:<<>>, _, args} = quoted, state) when is_list(args) do
6767
normalize_bitstring(quoted, state)
6868
end
6969

7070
# Atoms with interpolations
7171
defp do_normalize(
72-
{{:., dot_meta, [:erlang, :binary_to_atom]}, call_meta, [{:<<>>, _, _} = string, :utf8]},
72+
{{:., dot_meta, [:erlang, :binary_to_atom]}, call_meta,
73+
[{:<<>>, _, args} = string, :utf8]},
7374
state
74-
) do
75+
)
76+
when is_list(args) do
7577
dot_meta = patch_meta_line(dot_meta, state.parent_meta)
7678
call_meta = patch_meta_line(call_meta, dot_meta)
7779

@@ -166,8 +168,8 @@ defmodule Code.Normalizer do
166168
end
167169

168170
# Sigils
169-
defp do_normalize({sigil, meta, [{:<<>>, _, _} = string, modifiers]} = quoted, state)
170-
when is_atom(sigil) do
171+
defp do_normalize({sigil, meta, [{:<<>>, _, args} = string, modifiers]} = quoted, state)
172+
when is_list(args) and is_atom(sigil) do
171173
case Atom.to_string(sigil) do
172174
<<"sigil_", _name>> ->
173175
meta =
@@ -183,7 +185,7 @@ defmodule Code.Normalizer do
183185
end
184186

185187
# Tuples
186-
defp do_normalize({:{}, meta, args} = quoted, state) do
188+
defp do_normalize({:{}, meta, args} = quoted, state) when is_list(args) do
187189
{last_arg, args} = List.pop_at(args, -1)
188190

189191
if args != [] and match?([_ | _], last_arg) and keyword?(last_arg) do

lib/elixir/test/elixir/code_normalizer/quoted_ast_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ defmodule Code.Normalizer.QuotedASTTest do
66
describe "quoted_to_algebra/2" do
77
test "variable" do
88
assert quoted_to_string(quote(do: foo)) == "foo"
9+
assert quoted_to_string({:{}, [], nil}) == "{}"
910
end
1011

1112
test "local call" do

0 commit comments

Comments
 (0)