Skip to content

Commit 5c29b7e

Browse files
committed
Do not crash on preemptive errors with static atoms encoder, closes #13927
1 parent b5eb309 commit 5c29b7e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/elixir/src/elixir_tokenizer.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ interpolation_format({_, _, _} = Reason, _Extension, _Args, _Line, _Column, _Ope
13641364

13651365
%% Terminators
13661366

1367-
handle_terminator(Rest, _, _, Scope, {'(', {Line, Column, _}}, [{alias, _, Alias} | Tokens]) ->
1367+
handle_terminator(Rest, _, _, Scope, {'(', {Line, Column, _}}, [{alias, _, Alias} | Tokens]) when is_atom(Alias) ->
13681368
Reason =
13691369
io_lib:format(
13701370
"unexpected ( after alias ~ts. Function names and identifiers in Elixir "

lib/elixir/test/elixir/kernel/parser_test.exs

+10
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,16 @@ defmodule Kernel.ParserTest do
345345
{[line: 1, column: 1], "atom length must be less than system limit: ", atom}}
346346
end
347347

348+
test "avoids crashes on invalid AST" do
349+
encoder = fn atom, _meta -> {:ok, {:atom, [], [atom]}} end
350+
351+
assert {:error, {_, "missing terminator: )", ""}} =
352+
Code.string_to_quoted("Module(", static_atoms_encoder: encoder)
353+
354+
assert {:error, {_, "syntax error before: ", "'('"}} =
355+
Code.string_to_quoted("Module()", static_atoms_encoder: encoder)
356+
end
357+
348358
test "may return errors" do
349359
encoder = fn _atom, _meta ->
350360
{:error, "Invalid atom name"}

0 commit comments

Comments
 (0)