JuliaSyntax.jl icon indicating copy to clipboard operation
JuliaSyntax.jl copied to clipboard

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

Open c42f opened this issue 1 year ago • 0 comments

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.

c42f avatar Feb 06 '25 02:02 c42f