Skip to content

Commit 9ab879f

Browse files
N5N3LilithHafner
authored andcommitted
Fix findfirst(==(x::Integer), r::IdentityUnitRange) (JuliaLang#42756)
1 parent 1004a7a commit 9ab879f

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

base/array.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,7 @@ findfirst(p::Union{Fix2{typeof(isequal),Int},Fix2{typeof(==),Int}}, r::OneTo{Int
20702070
1 <= p.x <= r.stop ? p.x : nothing
20712071

20722072
findfirst(p::Union{Fix2{typeof(isequal),T},Fix2{typeof(==),T}}, r::AbstractUnitRange) where {T<:Integer} =
2073-
first(r) <= p.x <= last(r) ? 1+Int(p.x - first(r)) : nothing
2073+
first(r) <= p.x <= last(r) ? firstindex(r) + Int(p.x - first(r)) : nothing
20742074

20752075
function findfirst(p::Union{Fix2{typeof(isequal),T},Fix2{typeof(==),T}}, r::StepRange{T,S}) where {T,S}
20762076
isempty(r) && return nothing

test/ranges.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ end
348348
end
349349
end
350350
@testset "findfirst" begin
351+
@test findfirst(==(1), Base.IdentityUnitRange(-1:1)) == 1
351352
@test findfirst(isequal(3), Base.OneTo(10)) == 3
352353
@test findfirst(==(0), Base.OneTo(10)) == nothing
353354
@test findfirst(==(11), Base.OneTo(10)) == nothing

0 commit comments

Comments
 (0)