Skip to content

Commit 79ae08f

Browse files
author
José Valim
committed
Raise on invalid map syntax, closes #7268
1 parent 5d7ee90 commit 79ae08f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/elixir/src/elixir_tokenizer.erl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,10 @@ tokenize("\r\n" ++ Rest, Line, Column, Scope, Tokens) ->
473473

474474
% Others
475475

476+
tokenize([$%, $[ | Rest], Line, _Column, _Scope, Tokens) ->
477+
Reason = {Line, "expected %{ to define a map, got: ", [$%, $[]},
478+
{error, Reason, Rest, Tokens};
479+
476480
tokenize([$%, ${ | T], Line, Column, Scope, Tokens) ->
477481
tokenize([${ | T], Line, Column + 1, Scope, [{'%{}', {Line, Column, nil}} | Tokens]);
478482

lib/elixir/test/elixir/kernel/errors_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ defmodule Kernel.ErrorsTest do
108108
assert_eval_raise SyntaxError, msg, "foo:+1"
109109
end
110110

111+
test "invalid map start" do
112+
assert_eval_raise SyntaxError,
113+
"nofile:1: expected %{ to define a map, got: %[",
114+
"{:ok, %[], %{}}"
115+
end
116+
111117
test "sigil terminator" do
112118
assert_eval_raise TokenMissingError,
113119
"nofile:3: missing terminator: \" (for sigil ~r\" starting at line 1)",

0 commit comments

Comments
 (0)