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

lost expected assignment after "const" error #45024

Closed
JeffBezanson opened this issue Apr 18, 2022 · 1 comment · Fixed by #45344
Closed

lost expected assignment after "const" error #45024

JeffBezanson opened this issue Apr 18, 2022 · 1 comment · Fixed by #45344
Assignees
Labels
parser Language parsing and surface syntax regression Regression in behavior compared to a previous version
Milestone

Comments

@JeffBezanson
Copy link
Member

julia> const x
ERROR: `body` expression must terminate in `return`. Use `block` instead.

julia> const x::Int
# allowed

These both used to give the "expected assignment" error. This is because we need to parse const x inside struct definitions, and const x is a valid IR form but not generally allowed as input syntax. We need to either fix the error, or decide to allow const x (which declares x constant without giving it a value, which is a state we didn't want to be observable for too long).

@JeffBezanson JeffBezanson added regression Regression in behavior compared to a previous version parser Language parsing and surface syntax labels Apr 18, 2022
@JeffBezanson JeffBezanson added this to the 1.8 milestone Apr 18, 2022
@JeffBezanson JeffBezanson self-assigned this Apr 18, 2022
@JeffBezanson
Copy link
Member Author

If we fix this in lowering, there's a chance it could be breaking. We currently allow lowering code containing Expr(:const, :x). If we need to keep allowing that, the only way to give an error is during parsing, so we would need to selectively disable the error inside structs.

KristofferC pushed a commit that referenced this issue May 18, 2022
KristofferC pushed a commit that referenced this issue May 18, 2022
c42f added a commit to JuliaLang/JuliaSyntax.jl that referenced this issue Oct 26, 2022
Here I've replicated the fix from JuliaLang/julia#45024 so that
`const x` (ie, without an assignment) is only valid within a `struct`
and is otherwise an error.

Also avoid lowering the syntax `global const` into `const global` within
the parser; do this in Expr conversion instead. This more closely
reflects the structure of the source, allowing trivia attachment to be
more natural.
c42f added a commit to JuliaLang/JuliaSyntax.jl that referenced this issue Oct 26, 2022
Here I've replicated the fix from JuliaLang/julia#45024 so that
`const x` (ie, without an assignment) is only valid within a `struct`
and is otherwise an error.

Also avoid lowering the syntax `global const` into `const global` within
the parser; do this in `Expr` conversion instead. This more closely
reflects the structure of the source, allowing trivia attachment to be
more natural.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parser Language parsing and surface syntax regression Regression in behavior compared to a previous version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant