Skip to content

Disallow non-lhs all-underscore variable names #57626

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

Merged
merged 1 commit into from
Mar 25, 2025

Conversation

mlechu
Copy link
Member

@mlechu mlechu commented Mar 3, 2025

Addresses part of #57547. Currently, we only show the "all-underscore variable name not allowed" error when the offending symbol is in value position according to compile, but an earlier pass would keep them as raw symbols regardless. This led to raw symbols making their way out of lowering in an edge case.

This change: Reject all-underscore variables unless they're being written to. Also, improve an error message slighly.

Before:

julia> function f(); 1; _; end;
ERROR: syntax: all-underscore identifiers are write-only and their values cannot be used in expressions

julia> function f(); _; 1; end;
ERROR: Found raw symbol in code returned from lowering. Expected all symbols to have been resolved to GlobalRef or slots.

After:

julia> function f(); _; 1; end;
ERROR: syntax: all-underscore identifiers are write-only and their values cannot be used in expressions

Suggestions for more tests are welcome.

@mlechu mlechu added the compiler:lowering Syntax lowering (compiler front end, 2nd stage) label Mar 3, 2025
@topolarity topolarity added the backport 1.12 Change should be backported to release-1.12 label Mar 3, 2025
@Keno Keno requested a review from JeffBezanson March 4, 2025 04:32
@KristofferC KristofferC mentioned this pull request Mar 24, 2025
27 tasks
@JeffBezanson JeffBezanson merged commit 3360a44 into JuliaLang:master Mar 25, 2025
10 checks passed
KristofferC pushed a commit that referenced this pull request Mar 26, 2025
Addresses part of #57547. Currently, we only show the "all-underscore
variable name not allowed" error when the offending symbol is in value
position according to `compile`, but an earlier pass would keep them as
raw symbols regardless. This led to raw symbols making their way out of
lowering in an edge case.

This change: Reject all-underscore variables unless they're being
written to. Also, improve an error message slighly.

(cherry picked from commit 3360a44)
@KristofferC KristofferC removed the backport 1.12 Change should be backported to release-1.12 label Mar 31, 2025
mlechu added a commit to mlechu/JuliaLowering.jl that referenced this pull request Apr 1, 2025
JuliaLang/julia#54773, JuliaLang/julia#56713, JuliaLang/julia#57626. Some
changes omitted from `expand-decls` and `expand-assignment`
mlechu added a commit to mlechu/JuliaLowering.jl that referenced this pull request Apr 2, 2025
JuliaLang/julia#54773, JuliaLang/julia#56713, JuliaLang/julia#57626. Some
changes omitted from `expand-decls` and `expand-assignment`
mlechu added a commit to mlechu/JuliaLowering.jl that referenced this pull request Apr 2, 2025
An unfortunately large commit.  JuliaLang/julia#54773, JuliaLang/julia#56713,
JuliaLang/julia#57626. Some changes omitted from `expand-decls` and
`expand-assignment`.
mlechu added a commit to mlechu/JuliaLowering.jl that referenced this pull request Apr 2, 2025
An unfortunately large commit.  JuliaLang/julia#54773, JuliaLang/julia#56713,
JuliaLang/julia#57626. Some changes omitted from `expand-decls` and
`expand-assignment`.
mlechu added a commit to mlechu/JuliaLowering.jl that referenced this pull request Apr 2, 2025
JuliaLang/julia#54773, JuliaLang/julia#56713, JuliaLang/julia#57626. Some
changes omitted from `expand-decls` and `expand-assignment`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants