JuliaLang / JuliaLang/JuliaSyntax.jl
Named tuples without outer parentheses
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 293
- Forks
- 50
- PR merge metrics
- No merged PRs in 30d
Description
Named tuples are intended to be constructed with outer parentheses:
```julia
julia> (a = 1, b = 2)
(a = 1, b = 2)
```
But in some circumstances the outer parentheses are "unnecessary":
```julia
julia> (a = 1), (b = 2)
(a = 1, b = 2)
```
This happens because the parens here are grouping parentheses and these are ignored when assessing whether `=` is a key-value pair in a tuple or function call, rather than an assignment.
In a similar way, extra grouping parentheses within function calls are ignored when assessing whether `=` is a key-value pair:
```julia
julia> dump(Meta.parse("f((((a=1))))"))
Expr
head: Symbol call
args: Array{Any}((2,))
1: Symbol f
2: Expr
head: Symbol kw
args: Array{Any}((2,))
1: Symbol a
2: Int64 1
```
I think we should change this if possible, it's pretty awkward and confusing.
* The tuple example was found in https://discourse.julialang.org/t/unexpected-result-from-short-circuiting-inline-if/94400/8
* The function call example is mentioned in https://discourse.julialang.org/t/syntax-surprises/92369/35
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the tuple and function-call examples with Julia's Meta.parse, then trace how grouping parentheses are handled when deciding whether `=` is a key-value pair. Confirm the intended parsing behavior with the maintainers and add regression coverage showing that the outer parentheses requirement is enforced.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100