Skip to content

Commit cb67ac4

Browse files
authored
align checked_dims with Base by rejecting typemax(Int) (#39)
1 parent 75d8f75 commit cb67ac4

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/FixedSizeArrays.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ Base.isassigned(a::FixedSizeArray, i::Int) = isassigned(a.mem, i)
5050
checked_dims_impl(a::Int, ::Tuple{}) = a
5151
function checked_dims_impl(a::Int, t::Tuple{Int,Vararg{Int,N}}) where {N}
5252
b = first(t)
53+
tmax = typemax(a)
54+
if (a == tmax) || (b == tmax)
55+
throw(ArgumentError("array dimension size can't be the maximum representable value"))
56+
end
5357
if (a < 0) || (b < 0)
5458
throw(ArgumentError("array dimension size can't be negative"))
5559
end

test/runtests.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ end
5757
@test_throws ArgumentError FixedSizeArray{Float64,1}(undef, -1)
5858
@test_throws ArgumentError FixedSizeArray{Float64,1}(undef, (-1,))
5959
@test_throws ArgumentError FixedSizeArray{Float64,2}(undef, -1, -1)
60+
@test_throws ArgumentError FixedSizeArray{Float64,2}(undef, typemax(Int), 0)
6061
@test_throws ArgumentError FixedSizeArray{Float64,2}(undef, typemax(Int), typemax(Int))
61-
@test_throws ArgumentError FixedSizeArray{Float64,3}(undef, typemax(Int), typemax(Int), 2)
62-
@test_throws ArgumentError FixedSizeArray{Float64,4}(undef, typemax(Int), typemax(Int), 2, 4)
62+
@test_throws ArgumentError FixedSizeArray{Float64,3}(undef, typemax(Int)-1, typemax(Int)-1, 2)
63+
@test_throws ArgumentError FixedSizeArray{Float64,4}(undef, typemax(Int)-1, typemax(Int)-1, 2, 4)
6364
@testset "negative dimension size" begin
6465
for n 2:4
6566
funs = (

0 commit comments

Comments
 (0)