Skip to content

Commit ee0621f

Browse files
authored
Fix: lastindex for Numbers (#36314)
* Fix: lastindex for Numbers * Boundcheck for lastindex numbers * tests for lastindex, firstindex for numbers * include example test from #36311
1 parent 9cbe145 commit ee0621f

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

base/number.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ ndims(x::Number) = 0
6868
ndims(::Type{<:Number}) = 0
6969
length(x::Number) = 1
7070
firstindex(x::Number) = 1
71+
firstindex(x::Number, d::Int) = d < 1 ? throw(BoundsError()) : 1
7172
lastindex(x::Number) = 1
73+
lastindex(x::Number, d::Int) = d < 1 ? throw(BoundsError()) : 1
7274
IteratorSize(::Type{<:Number}) = HasShape{0}()
7375
keys(::Number) = OneTo(1)
7476

test/numbers.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,7 +2401,12 @@ end
24012401
@test size(1) == ()
24022402
@test length(1) == 1
24032403
@test firstindex(1) == 1
2404+
@test firstindex(1, 1) == 1
2405+
@test_throws BoundsError firstindex(1,0)
24042406
@test lastindex(1) == 1
2407+
@test lastindex(1, 1) == 1
2408+
@test 1[end,end] == 1
2409+
@test_throws BoundsError lastindex(1,0)
24052410
@test eltype(Integer) == Integer
24062411
end
24072412

0 commit comments

Comments
 (0)