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

ERROR: syntax: invalid named tuple element misleading message #30030

Closed
goretkin opened this issue Nov 14, 2018 · 2 comments
Closed

ERROR: syntax: invalid named tuple element misleading message #30030

goretkin opened this issue Nov 14, 2018 · 2 comments
Assignees
Labels
error handling Handling of exceptions by Julia or the user parser Language parsing and surface syntax

Comments

@goretkin
Copy link
Contributor

The following code produces the following syntax error.

julia> d = 4
4

julia> (
           a=2,
           b=3,
           c = (d=d)
           )
ERROR: syntax: invalid named tuple element "2"

The fix is to add a trailing , (comma) to the named tuple of one element, which is not quite what the error message says.

julia> (
           a=2,
           b=3,
           c = (d=d,)
           )
(a = 2, b = 3, c = (d = 4,))

julia> versioninfo()
Julia Version 1.0.2
Commit d789231e99 (2018-11-08 20:11 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Core(TM) i7-4960HQ CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, haswell)

(I ran into this when porting code away from using NamedTuples.jlon juia v0.6)

@StefanKarpinski StefanKarpinski added the parser Language parsing and surface syntax label Nov 14, 2018
@JeffBezanson
Copy link
Member

Thanks for catching this. There is indeed a glaring bug here, but after fixing it there won't be an error, since (d=d) is a valid expression. For example f(a=(b=c)) assigns b = c, then passes the value of c as the a argument to f. I guess we can decide separately whether to change anything about that.

@JeffBezanson JeffBezanson added the error handling Handling of exceptions by Julia or the user label Nov 15, 2018
@goretkin
Copy link
Contributor Author

I didn't catch that, but of course you're right. I had some non-syntax bugs in my code because @nt(a=3) produced a tuple, but (a=3) on v0.7 did not.

I think it's perfectly okay if there is no error for my original code. (3) doesn't produce a tuple, and neither does (a=3).

@KristofferC KristofferC mentioned this issue Nov 19, 2018
61 tasks
KristofferC pushed a commit that referenced this issue Nov 28, 2018
KristofferC pushed a commit that referenced this issue Dec 12, 2018
KristofferC pushed a commit that referenced this issue Feb 11, 2019
KristofferC pushed a commit that referenced this issue Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error handling Handling of exceptions by Julia or the user parser Language parsing and surface syntax
Projects
None yet
Development

No branches or pull requests

3 participants