From 34876e8bf8ea72e992ad512cacd950ed80db4e1b Mon Sep 17 00:00:00 2001 From: Or Neeman Date: Sun, 8 Feb 2015 16:56:14 -0600 Subject: [PATCH] Throw syntax error for `:foo.Bar` Closes #2986 --- lib/elixir/src/elixir_parser.yrl | 7 +++++++ lib/elixir/test/erlang/atom_test.erl | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/lib/elixir/src/elixir_parser.yrl b/lib/elixir/src/elixir_parser.yrl index 288e47848f..59d9d30ce5 100644 --- a/lib/elixir/src/elixir_parser.yrl +++ b/lib/elixir/src/elixir_parser.yrl @@ -596,6 +596,9 @@ build_block(Exprs) -> {'__block__', [], Exp build_dot_alias(Dot, {'__aliases__', _, Left}, {'aliases', _, Right}) -> {'__aliases__', meta(Dot), Left ++ Right}; +build_dot_alias(_Dot, Atom, {'aliases', {Line, _, _}, _}) when is_atom(Atom) -> + throw_bad_atom(Line); + build_dot_alias(Dot, Other, {'aliases', _, Right}) -> {'__aliases__', meta(Dot), [Other|Right]}. @@ -744,3 +747,7 @@ throw_no_parens_many_strict(Token) -> throw(Line, "unexpected comma. Parentheses are required to solve ambiguity " "in nested calls. Syntax error before: ", "','"). + +throw_bad_atom(Line) -> + throw(Line, "atom cannot be followed by an alias. If the '.' was meant to be " + "part of the atom's name, the name must be quoted. Syntax error before: ", "'.'"). diff --git a/lib/elixir/test/erlang/atom_test.erl b/lib/elixir/test/erlang/atom_test.erl index ea78e7c118..10134d9dfe 100644 --- a/lib/elixir/test/erlang/atom_test.erl +++ b/lib/elixir/test/erlang/atom_test.erl @@ -39,3 +39,7 @@ atom_with_interpolation_test() -> quoted_atom_chars_are_escaped_test() -> {'"',[]} = eval(":\"\\\"\""). + +atom_dot_alias_test() -> + ?assertError(#{'__struct__' := 'Elixir.SyntaxError'}, eval(":foo.Bar")), + ?assertError(#{'__struct__' := 'Elixir.SyntaxError'}, eval(":\"foo\".Bar")).