Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong error msg when macro called with wrong number of args #8697

Open
timotheecour opened this issue Aug 20, 2018 · 2 comments
Open

wrong error msg when macro called with wrong number of args #8697

timotheecour opened this issue Aug 20, 2018 · 2 comments

Comments

@timotheecour
Copy link
Member

reduced from a more complex example:

in case1, I would expect error message to be something like: bar expected 2 arguments (lambda: untyped, arg:typed) ; got 3

instead, currently the compiler tries to evaluate fun, which fails because it's not meant to be evaluated in this context.

in summary: we should evaluate number of arguments first before any other mismatch logic.
Is there anything blocking this logic? (eg: varargs[untyped] ?)

import macros

macro bar*(lambda: untyped, arg:typed):untyped=
  dumpTree(lambda)
  result = newStmtList()

block:
  template foo[T](fun: untyped, a:T, b:T): auto =
    when defined(case1):
      discard bar(fun, a, b)
    when defined(case2):
      discard bar(fun, a)
    0

  discard foo(u1 => u1, 2, 3)
rnim -d:case2 bugs/compiler/t23_errmsg_confusing_with_macro_num_arg_mismatch.nim
nim c --nimcache:/tmp/nim//nimcache/ -o:/tmp/nim//app -r -d:case2 bugs/compiler/t23_errmsg_confusing_with_macro_num_arg_mismatch.nim
Hint: used config file '/Users/timothee/git_clone/nim/Nim/config/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/.config/nim/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/git_clone/nim/timn/nim.cfg' [Conf]
Ident "lambda"
/Users/timothee/git_clone/nim/timn/bugs/compiler/t23_errmsg_confusing_with_macro_num_arg_mismatch.nim(7, 1) template/generic instantiation from here
/Users/timothee/git_clone/nim/timn/bugs/compiler/t23_errmsg_confusing_with_macro_num_arg_mismatch.nim(15, 14) template/generic instantiation from here
/Users/timothee/git_clone/nim/timn/bugs/compiler/t23_errmsg_confusing_with_macro_num_arg_mismatch.nim(12, 18) Error: expression '' has no type (or is ambiguous)
        discard bar(fun, a)
                   ^
rnim -d:case1 bugs/compiler/t23_errmsg_confusing_with_macro_num_arg_mismatch.nim
nim c --nimcache:/tmp/nim//nimcache/ -o:/tmp/nim//app -r -d:case1 bugs/compiler/t23_errmsg_confusing_with_macro_num_arg_mismatch.nim
Hint: used config file '/Users/timothee/git_clone/nim/Nim/config/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/.config/nim/nim.cfg' [Conf]
Hint: used config file '/Users/timothee/git_clone/nim/timn/nim.cfg' [Conf]
Ident "lambda"
/Users/timothee/git_clone/nim/timn/bugs/compiler/t23_errmsg_confusing_with_macro_num_arg_mismatch.nim(7, 1) template/generic instantiation from here
/Users/timothee/git_clone/nim/timn/bugs/compiler/t23_errmsg_confusing_with_macro_num_arg_mismatch.nim(15, 18) Error: undeclared identifier: '=>'
    discard foo(u1 => u1, 2, 3)
                   ^
@Araq
Copy link
Member

Araq commented Aug 21, 2018

in summary: we should evaluate number of arguments first before any other mismatch logic.

Why? Which section of the spec covers that "should"?

@jangko
Copy link
Contributor

jangko commented May 30, 2019

simpler working example:

type
  Fruit = enum
    apple
    banana
    orange
    
macro hello(x, y: untyped) =
  echo "OK"
  
hello(apple, banana, orange)

got a less confusing error message:

abc.nim(12, 6) Error: type mismatch: got <Fruit, Fruit, Fruit>
but expected one of:
macro hello(x, y: untyped)

expression: hello(apple, banana, orange)

this one produces a really confusing error message(using undeclared identifier)

macro hello(x, y: untyped) =
  echo "OK"
  
hello(apple, banana, orange)
apc.nim(12, 7) Error: undeclared identifier: 'apple'

expect something like:

abc.nim(12, 6) Error: type mismatch: got <void, void, void> # `void` can be replaced with something else
but expected one of:
macro hello(x, y: untyped)

expression: hello(apple, banana, orange)

or a more meaningful error message like @timotheecour wants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants