Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difference in parsing x.[y] to Expr #396

Open
c42f opened this issue Dec 4, 2023 · 2 comments
Open

Difference in parsing x.[y] to Expr #396

c42f opened this issue Dec 4, 2023 · 2 comments

Comments

@c42f
Copy link
Member

c42f commented Dec 4, 2023

Likely due to #325 we have the following difference:

julia> dump(parsestmt(Expr, "x.[y]"))
Expr
  head: Symbol .
  args: Array{Any}((2,))
    1: Symbol x
    2: QuoteNode
      value: Expr
        head: Symbol vect
        args: Array{Any}((1,))
          1: Symbol y

julia> dump(JuliaSyntax.fl_parse(Expr, "x.[y]"))
Expr
  head: Symbol .
  args: Array{Any}((2,))
    1: Symbol x
    2: Expr
      head: Symbol quote
      args: Array{Any}((1,))
        1: Expr
          head: Symbol vect
          args: Array{Any}((1,))
            1: Symbol y
@c42f
Copy link
Member Author

c42f commented Dec 4, 2023

Ok, so this is related to the logic at

JuliaSyntax.jl/src/expr.jl

Lines 287 to 289 in acb609d

if !@isexpr(a2, :quote) && !(a2 isa QuoteNode)
args[2] = QuoteNode(a2)
end

I think the subtle point here is that the right hand side of . should always be inert: that is, QuoteNode rather than Expr(:quote) in the AST. The flisp parser has a special case for this in parsing of x.$y and emits inert in that case. But that's technically incorrect and breaks expansion of quote expressions like the following

julia> y = :a
:a

julia> quote
           x.$y
       end
quote
    #= REPL[33]:2 =#
    x.a
end

julia> quote
           x.[$y]
       end
quote
    #= REPL[34]:2 =#
    x.:([$(Expr(:$, :y))])
end

See? In that second case the $y doesn't get expanded.

However! In current JuliaSyntax main branch we have the following which is correct

julia> JuliaSyntax.enable_in_core!(freeze_world_age=false)

julia> quote
           x.[$y]
       end
quote
    #= REPL[36]:2 =#
    x.:([a])
end

So while this is a regression, the new behavior is also technically correct, and a bugfix. So we need to decide what to do.

@c42f
Copy link
Member Author

c42f commented Dec 4, 2023

This syntax was found in the General registry in Accessors.jl and Setfield.jl (the predecessor package of accessors). But in these cases the syntax was only used in a test case for macro error handling - so nobody should be actually using this syntax with those packages.

See jw3126/Setfield.jl#83

@c42f c42f changed the title regression parsing x.[y] Difference in parsing x.[y] to Expr Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant