Skip to content

Commit

Permalink
Make inbounds macros expression-like (#25033)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski authored Dec 19, 2017
1 parent c16c0cb commit ea3639e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,9 @@ end
macro inbounds(blk)
return Expr(:block,
Expr(:inbounds, true),
esc(blk),
Expr(:inbounds, :pop))
Expr(:local, Expr(:(=), :val, esc(blk))),
Expr(:inbounds, :pop),
:val)
end

"""
Expand Down
12 changes: 12 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2008,6 +2008,18 @@ end
@test typeof(.~A) == Vector{Int}
end

# @inbounds is expression-like, returning its value; #15558
@testset "expression-like inbounds" begin
local A = [1,2,3]
@test (@inbounds A[1]) == 1
f(A, i) = @inbounds i == 0 ? (return 0) : A[i]
@test f(A, 0) == 0
@test f(A, 1) == 1
g(A, i) = (i == 0 ? (@inbounds return 0) : (@inbounds A[i]))
@test g(A, 0) == 0
@test g(A, 1) == 1
end

@testset "issue #16247" begin
local A = zeros(3,3)
@test size(A[:,0x1:0x2]) == (3, 2)
Expand Down

0 comments on commit ea3639e

Please sign in to comment.