Skip to content

Commit 70692e6

Browse files
author
José Valim
committed
Improve token errors for aliases, closes #2818
Signed-off-by: José Valim <[email protected]>
1 parent 529d584 commit 70692e6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/elixir/src/elixir_errors.erl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,16 @@ parse_error(Line, File, Error, <<>>) ->
5555
parse_error(Line, File, <<"syntax error before: ">>, <<"'end'">>) ->
5656
do_raise(Line, File, 'Elixir.SyntaxError', <<"unexpected token: end">>);
5757

58-
%% Binaries are wrapped in [<<...>>], so we need to unwrap them
58+
%% Aliases are wrapped in ['']
59+
parse_error(Line, File, Error, <<"['", Token/binary>>) when is_binary(Error) ->
60+
Rest =
61+
case binary:split(Token, <<"'">>) of
62+
[Part, _] -> Part;
63+
_ -> <<>>
64+
end,
65+
do_raise(Line, File, 'Elixir.SyntaxError', <<Error/binary, Rest/binary>>);
66+
67+
%% Binaries (and interpolation) are wrapped in [<<...>>]
5968
parse_error(Line, File, Error, <<"[", _/binary>> = Full) when is_binary(Error) ->
6069
Rest =
6170
case binary:split(Full, <<"<<">>) of

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ defmodule Kernel.ErrorsTest do
2020
"nofile:1: syntax error before: \"world\"",
2121
'"hello" "world"'
2222

23+
assert_compile_fail SyntaxError,
24+
"nofile:1: syntax error before: Foobar",
25+
'1 Foobar'
26+
2327
assert_compile_fail SyntaxError,
2428
"nofile:1: syntax error before: foo",
2529
'Foo.:foo'

0 commit comments

Comments
 (0)