Skip to content

Commit 6024014

Browse files
author
José Valim
committed
Improve error message on unclosed interpolation/string, closes #794
1 parent 01d7e21 commit 6024014

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/elixir/src/elixir_interpolation.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ extract(Line, _File, _Interpol, [], _Buffer, [], _Output, Last) ->
1919
extract(Line, File, _Interpol, [Last|Remaining], Buffer, [], Output, Last) ->
2020
finish_extraction(Line, File, Buffer, Output, Remaining);
2121

22-
extract(Line, _File, _Interpol, [Last], _Buffer, Search, _Output, Last) ->
23-
{ error, { Line, io_lib:format("unexpected end of string: ~ts", [[hd(Search)]]), [Last] } };
22+
extract(Line, _File, _Interpol, End, _Buffer, Search, _Output, Last) when End == [Last]; End == [] ->
23+
{ error, { Line, io_lib:format("missing terminator: ~ts", [[Last]]), [] } };
2424

2525
extract(Line, File, Interpol, [$\n|Rest], Buffer, Search, Output, Last) ->
2626
extract(Line+1, File, Interpol, Rest, [$\n|Buffer], Search, Output, Last);

lib/elixir/test/erlang/string_test.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ bin_string_with_escaped_interpolation_test() ->
9898
{<<"f#{'o}o">>, _} = eval("\"f\\#{'o}o\"").
9999

100100
invalid_string_interpolation_test() ->
101-
?assertError({'Elixir.SyntaxError', _, _, _, _}, eval("\"f#{{}o\"")).
101+
?assertError({'Elixir.TokenMissingError', _, _, _, _}, eval("\"f#{some\"")),
102+
?assertError({'Elixir.TokenMissingError', _, _, _, _}, eval("\"f#{1+")).
102103

103104
unterminated_string_interpolation_test() ->
104105
?assertError({'Elixir.TokenMissingError', _, _, _, _}, eval("\"foo")).

0 commit comments

Comments
 (0)