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

rename variable used in inbounds to avoid accidental collisions due to macro hygiene bug #54613

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

KristofferC
Copy link
Member

Fixes #54417

@KristofferC KristofferC added the macros @macros label May 29, 2024
@@ -861,9 +861,9 @@ end
macro inbounds(blk)
return Expr(:block,
Expr(:inbounds, true),
Expr(:local, Expr(:(=), :val, esc(blk))),
Expr(:local, Expr(:(=), :val_49f6338b, esc(blk))),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gensym? But as was pointed out in the original issue, the macro is fine as written, the current behavior is a bug. Maybe leave a comment that effect?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gensym is not defined during bootstrapping so this seemed easiest.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is off-topic, but I wonder if reserved words might be useful in these cases. cf. (PR #51215)
Of course, we still need to be careful to avoid collisions in Base and stdlibs.

end
end

@testset "inbounds hygien confusion" begin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@testset "inbounds hygien confusion" begin
@testset "inbounds hygiene confusion" begin

@giordano giordano changed the title rename variable used in inbounds to avoid accidental collisions due to macry hygiene bug rename variable used in inbounds to avoid accidental collisions due to macro hygiene bug May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
macros @macros
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@inbounds overrides val variable in macros. Wrong usage of local
5 participants