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

Command calls don't work with a single named arg #15050

Closed
dawkot opened this issue Jul 23, 2020 · 2 comments · Fixed by #20994
Closed

Command calls don't work with a single named arg #15050

dawkot opened this issue Jul 23, 2020 · 2 comments · Fixed by #20994
Labels

Comments

@dawkot
Copy link

dawkot commented Jul 23, 2020

Example

proc myProc(x = 0) = discard

myProc x=1 # error: undeclared identifier: 'x'

Additional Information

@metagn
Copy link
Collaborator

metagn commented Jul 30, 2020

It only works when the first argument is unnamed.

proc foo(a, b: int) = echo a + b

foo 4, b = 5 # 9

@timotheecour
Copy link
Member

timotheecour commented Jul 30, 2020

IIUC it's because of precedence rules, look at

import macros
macro deb(a): untyped =
  echo a.treeRepr
  echo a.repr
deb:
  myProc x=1
StmtList
  Asgn
    Command
      Ident "myProc"
      Ident "x"
    IntLit 1

myProc x = 1

EDIT: looks like a common gotcha, see this recent post: https://forum.nim-lang.org/t/8037

the question is: how can we improve things here without introducing parser ambiguties?

on possible rule is:

myProc x = 1 # still parsed as (myProc x) = 1
myProc x = 1, expr # previously rejected by parser, now accepted as myProc(x = 1, expr)

which does not sound ambiguous

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