Skip to content

Commit 8517eb3

Browse files
jishnubKristofferC
authored andcommitted
Add type assertion in iterate for logicalindex (#53015)
The type-assertion helps convey the information that `iterate(tail(s)...)` would never return `nothing`, which makes JET happy. On master ```julia julia> L = Base.LogicalIndex([true]) 1-element Base.LogicalIndex{Int64, Vector{Bool}}: 1 julia> @report_call iterate(L) ═════ 2 possible errors found ═════ ┌ iterate(L::Base.LogicalIndex{Int64, Vector{Bool}}) @ Base ./multidimensional.jl:778 │┌ iterate(L::Base.LogicalIndex{Int64, Vector{Bool}}, s::Tuple{Int64, LinearIndices{1, Tuple{Base.OneTo{Int64}}}}) @ Base ./multidimensional.jl:789 ││┌ indexed_iterate(I::Nothing, i::Int64) @ Base ./tuple.jl:94 │││ no matching method found `iterate(::Nothing)`: x = iterate(I::Nothing) ││└──────────────────── ││┌ indexed_iterate(I::Nothing, i::Int64, state::Int64) @ Base ./tuple.jl:99 │││ no matching method found `iterate(::Nothing, ::Int64)`: x = iterate(I::Nothing, state::Int64) ``` This PR ```julia julia> @report_call iterate(L) No errors detected ``` Close JuliaArrays/StaticArrays.jl#1225 (cherry picked from commit 32ad80b)
1 parent 4f3a3ae commit 8517eb3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

base/multidimensional.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,11 +810,11 @@ end
810810
n = s[1]
811811
n > length(L) && return nothing
812812
#unroll once to help inference, cf issue #29418
813-
idx, i = iterate(tail(s)...)
813+
idx, i = iterate(tail(s)...)::Tuple{Any,Any}
814814
s = (n+1, s[2], i)
815815
L.mask[idx] && return (idx, s)
816816
while true
817-
idx, i = iterate(tail(s)...)
817+
idx, i = iterate(tail(s)...)::Tuple{Any,Any}
818818
s = (n+1, s[2], i)
819819
L.mask[idx] && return (idx, s)
820820
end

0 commit comments

Comments
 (0)