Skip to content

Make no-index A[] check bounds like everyone else #24236

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 3 commits into from
Oct 23, 2017
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fixup tests
mbauman committed Oct 20, 2017

Verified

This commit was signed with the committer’s verified signature.
snyk-bot Snyk bot
commit c3789a54e359a3605aa75f91c7f4ee46e4403fcc
28 changes: 18 additions & 10 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
@@ -301,7 +301,7 @@ function test_scalar_indexing(::Type{T}, shape, ::Type{TestAbstractArray}) where
end
end
# Test zero-dimensional accesses
@test A[] == B[] == A[1] == B[1] == 1
@test A[1] == B[1] == 1
# Test multidimensional scalar indexed assignment
C = T(Int, shape)
D1 = T(Int, shape)
@@ -361,9 +361,17 @@ function test_scalar_indexing(::Type{T}, shape, ::Type{TestAbstractArray}) where
end
@test C == B == A
# Test zero-dimensional setindex
A[] = 0; B[] = 0
@test A[] == B[] == 0
@test A == B
if length(A) == 1
A[] = 0; B[] = 0
@test A[] == B[] == 0
@test A == B
else
# TODO: Re-enable after PLI deprecation
# @test_throws BoundsError A[] = 0
# @test_throws BoundsError B[] = 0
# @test_throws BoundsError A[]
# @test_throws BoundsError B[]
end
end

function test_vector_indexing(::Type{T}, shape, ::Type{TestAbstractArray}) where T
@@ -489,10 +497,10 @@ function test_getindex_internals(::Type{T}, shape, ::Type{TestAbstractArray}) wh
A = reshape(collect(1:N), shape)
B = T(A)

@test getindex(A) == 1
@test getindex(B) == 1
@test Base.unsafe_getindex(A) == 1
@test Base.unsafe_getindex(B) == 1
@test getindex(A, 1) == 1
@test getindex(B, 1) == 1
@test Base.unsafe_getindex(A, 1) == 1
@test Base.unsafe_getindex(B, 1) == 1
end

function test_getindex_internals(::Type{TestAbstractArray})
@@ -509,8 +517,8 @@ function test_setindex!_internals(::Type{T}, shape, ::Type{TestAbstractArray}) w
A = reshape(collect(1:N), shape)
B = T(A)

Base.unsafe_setindex!(B, 1)
@test B[1] == 1
Base.unsafe_setindex!(B, 2, 1)
@test B[1] == 2
end

function test_setindex!_internals(::Type{TestAbstractArray})
13 changes: 10 additions & 3 deletions test/bitarray.jl
Original file line number Diff line number Diff line change
@@ -206,9 +206,16 @@ timesofar("constructors")
@testset "Indexing" begin
@testset "0d for size $sz" for (sz,T) in allsizes
b1 = rand!(falses(sz...))
@check_bit_operation getindex(b1) Bool
@check_bit_operation setindex!(b1, true) T
@check_bit_operation setindex!(b1, false) T
if length(b1) == 1
@check_bit_operation getindex(b1) Bool
@check_bit_operation setindex!(b1, true) T
@check_bit_operation setindex!(b1, false) T
else
# TODO: Re-enable after PLI deprecation is removed
# @test_throws getindex(b1)
# @test_throws setindex!(b1, true)
# @test_throws setindex!(b1, false)
end
end

@testset "linear for size $sz" for (sz,T) in allsizes[2:end]
2 changes: 1 addition & 1 deletion test/core.jl
Original file line number Diff line number Diff line change
@@ -2332,7 +2332,7 @@ end

# pull request #9534
@test try; a,b,c = 1,2; catch ex; (ex::BoundsError).a === (1,2) && ex.i == 3; end
@test try; [][]; catch ex; isempty((ex::BoundsError).a::Array{Any,1}) && ex.i == (1,); end
# @test try; [][]; catch ex; isempty((ex::BoundsError).a::Array{Any,1}) && ex.i == (1,); end # TODO: Re-enable after PLI
@test try; [][1,2]; catch ex; isempty((ex::BoundsError).a::Array{Any,1}) && ex.i == (1,2); end
@test try; [][10]; catch ex; isempty((ex::BoundsError).a::Array{Any,1}) && ex.i == (10,); end
f9534a() = (a=1+2im; getfield(a, -100))