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

arr[var"end"] is the same as arr[end] #57269

Open
mlechu opened this issue Feb 5, 2025 · 3 comments · Fixed by JuliaObjects/Accessors.jl#196, jw3126/Setfield.jl#182 or wdebeaum/PEG.jl#7 · May be fixed by #57368
Open

arr[var"end"] is the same as arr[end] #57269

mlechu opened this issue Feb 5, 2025 · 3 comments · Fixed by JuliaObjects/Accessors.jl#196, jw3126/Setfield.jl#182 or wdebeaum/PEG.jl#7 · May be fixed by #57368
Assignees

Comments

@mlechu
Copy link
Member

mlechu commented Feb 5, 2025

Brought up in #56936 (thanks @martinholters for the example):

julia> let var"end"=1; (1:10)[var"end"]; end
10 # anything else than "end", and you get 1
@Keno
Copy link
Member

Keno commented Feb 5, 2025

I think the parser should probably parse the end atom as `(end) rather than 'end (and same for begin), with appropriate adjustments to the rest of lowering.

The parse-atom code is here in the flisp parser: https://github.com/JuliaLang/julia/blob/master/src/julia-parser.scm#L2477
The JuliaSyntax parser actually already recognizes it as a keyword and then explicitly maps it back to an identifier here: https://github.com/JuliaLang/JuliaSyntax.jl/blob/2e965a159dd9f87d216d2d50ecbd2ed4f9af2c5a/src/parser.jl#L3632, so that could be appropriately tweaked.

The primary lowering code that deals with begin/end is here: https://github.com/JuliaLang/julia/blob/master/src/julia-syntax.scm#L115-L130 although grep for 'end and 'begin for other places.

@JeffBezanson
Copy link
Member

That sounds right to me.

@vtjnash
Copy link
Member

vtjnash commented Feb 5, 2025

Even if we change the parser though, printing would still be wrong unless it correctly detects the context, and additionally would be a huge pain to deparse in situations where the expr was not expected. It is still probably the right thing to do (like was done for true/false), but is quite separate from the correct printing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment