JuliaLang / JuliaLang/JuliaSyntax.jl

Parentheses parsed as tuple in `::(x) -> y` and `&(x) -> y`

Open
#535 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Julia
Stars
293
Forks
50
PR merge metrics
No merged PRs in 30d

Description

As reported in https://github.com/JuliaLang/julia/issues/57223 and partly fixed in #534 the parsing change in #522 had the unintended consequences of parsing parentheses as a tuple in these cases.

Basically, we can't reliably look ahead at the `K"->"` token when parsing parentheses in `parse_paren()` if any construct with higher precedence is currently being parsed on the left hand side of the `()`. Luckily there's very few such constructs - it appears only the unary prefixes `$`, `&` and `::`. I've fixed unary `$` in #534 but unary `&` and unary `::` are entangled in `where` parsing so are a bit more difficult to fix. Thus the obscure and probably-useless syntaxes `::(T) -> y` and `&(x) -> y` are currently broken.

It's hard to imagine what `::(T) -> y` could be useful for, but it is valid syntax so we should still fix this. `&(T) -> y` is even less useful because unary `&` has been invalid in lowering for a very long time (Julia 0.4 or 0.3 ish ??), but perhaps a macro somewhere could rely on it.

The most obvious way to fix this is to ensure `has_unary_prefix` from #534 is also applied to parsing of `::` and `&` which might require carefully adding it to the arguments of a few more functions.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.