JuliaLang / JuliaSyntax.jl

The Julia compiler frontend
Other
272 stars 35 forks source link

Interpolated `getproperty` syntax error #426

Open dennisYatunin opened 6 months ago

dennisYatunin commented 6 months ago

I am seeing the following unexpected behavior with Julia version 1.10.2:

julia> foo(x) = x.:($(1 + 2)) + 0
ERROR: syntax: invalid syntax "x.((1 + 2))" around REPL[1]:1
Stacktrace:
 [1] top-level scope
   @ REPL[1]:1

julia> foo(x) = x.:($(1 + 2)) += 0
ERROR: syntax: invalid syntax "x.(SSAValue(9))" around REPL[2]:1
Stacktrace:
 [1] top-level scope
   @ REPL[2]:1

julia> foo(x) = x.:($(1 + 2)) .+= 0
ERROR: syntax: invalid syntax "x.(SSAValue(16))" around REPL[3]:1
Stacktrace:
 [1] top-level scope
   @ REPL[3]:1

julia> foo(x) = x.:($(1 + 2)) .= 0
foo (generic function with 1 method)

All of these definitions work when they are written out as calls to getproperty, so it looks like this is hitting some uncaught edge case for expression interpolation.

c42f commented 2 months ago

This error arises from lowering, it's not really a JuliaSyntax issue:

julia> (101im).:($(:im))
101

julia> (101im).:($(Symbol("im")))
ERROR: syntax: invalid syntax "(101 * im).(Symbol("im"))" around REPL[25]:1
Stacktrace:
 [1] top-level scope
   @ REPL[25]:1

# and yet this parses fine:
julia> :((101im).:($(Symbol("im"))))
:((101im).:($(Expr(:$, :(Symbol("im"))))))

The fact that x.:($y) works at all, in any cases, might just be a mistake? I'm not sure. getproperty(x,y) seems a lot better to me!