Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expr(:inbounds, :pop),
:val)
:val_49f6338b)
end

"""
Expand Down
14 changes: 14 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2123,3 +2123,17 @@ end
@test one(Mat([1 2; 3 4])) == Mat([1 0; 0 1])
@test one(Mat([1 2; 3 4])) isa Mat
end


macro foo_54417(x,i)
quote
val = $x
@inbounds $x[$i]
val
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

z = [1,2,3]
@test (@foo_54417 z 1) == z
end