Skip to content

Commit e999642

Browse files
author
José Valim
committed
Improve syntax error on invalid calls
Closes #1847
1 parent 773d4b0 commit e999642

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/elixir/src/elixir_translator.erl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,12 @@ translate_each({ { '.', _, [Expr] }, Meta, Args }, S) when is_list(Args) ->
425425

426426
%% Invalid calls
427427

428-
translate_each({ Invalid, Meta, Args }, S) when is_list(Meta) and is_list(Args) ->
429-
syntax_error(Meta, S#elixir_scope.file, "unexpected parenthesis after ~ts",
428+
translate_each({ { '.', _, [Invalid, _] }, Meta, Args }, S) when is_list(Meta) and is_list(Args) ->
429+
syntax_error(Meta, S#elixir_scope.file, "invalid remote call on ~ts",
430+
['Elixir.Macro':to_string(Invalid)]);
431+
432+
translate_each({ _, Meta, Args } = Invalid, S) when is_list(Meta) and is_list(Args) ->
433+
syntax_error(Meta, S#elixir_scope.file, "invalid call ~ts",
430434
['Elixir.Macro':to_string(Invalid)]);
431435

432436
translate_each({ _, _, _ } = Tuple, S) ->

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,14 @@ defmodule Kernel.ErrorsTest do
202202
'quote 1'
203203
end
204204

205-
test :invalid_parens do
205+
test :invalid_calls do
206206
assert_compile_fail SyntaxError,
207-
"nofile:1: unexpected parenthesis after foo(1)",
207+
"nofile:1: invalid call foo(1)(2)",
208208
'foo(1)(2)'
209+
210+
assert_compile_fail SyntaxError,
211+
"nofile:1: invalid remote call on 1",
212+
'1.foo'
209213
end
210214

211215
test :unhandled_stab do

0 commit comments

Comments
 (0)