JuliaLang / JuliaLang/JuliaSyntax.jl

Named tuples without outer parentheses

Open
#194 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

syntax wat
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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.