aviatesk / JET.jl

An experimental code analyzer for Julia. No need for additional type annotations.

Home Page:https://aviatesk.github.io/JET.jl/dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JET should report dangerous indexing

aviatesk opened this issue · comments

MRE:

julia> report_call((Vector{Int},)) do xs
           xs[findfirst(>(0), xs)]
       end
No errors detected

This should report the possibility of the following case:

julia> report_call((Vector{Int},)) do xs
           xs[nothing]
       end
═════ 1 possible error found ═════
┌ (::var"#18#19")(xs::Vector{Int64}) @ Main ./REPL[7]:2
│┌ getindex(A::Vector{Int64}, I::Nothing) @ Base ./abstractarray.jl:1288
││┌ to_indices(A::Vector{Int64}, I::Tuple{Nothing}) @ Base ./indices.jl:345
│││┌ to_indices(A::Vector{Int64}, inds::Tuple{Base.OneTo{Int64}}, I::Tuple{Nothing}) @ Base ./indices.jl:354
││││┌ _to_indices1(A::Vector{Int64}, inds::Tuple{Base.OneTo{Int64}}, I1::Nothing) @ Base ./indices.jl:359
│││││┌ to_index(A::Vector{Int64}, i::Nothing) @ Base ./indices.jl:277
││││││┌ to_index(i::Nothing) @ Base ./indices.jl:300
│││││││ may throw: Base.throw(Base.ArgumentError(string("invalid index: ", Base.limitrepr(i::Nothing)::String, " of type ", Base.typeof(i::Nothing)::Type{Nothing})::String)::ArgumentError)
││││││└────────────────────

Maybe we should promote UncaughtExceptionReport reported from to_index methods to MethodErrorReport.