Strange error after an error occurred with `isvalid(::AbstractString, ::Integer)`


#1

I got the following:

  Got an exception of type MethodError outside of a @test
┌ Error: Error showing method candidates, aborted
│   exception =
│    MethodError: no method matching length(::Type{Tuple{UTF16Str,Int64}})
│    Closest candidates are:
│      length(::SimpleVector) at essentials.jl:544
│      length(::Base.MethodList) at reflection.jl:671
│      length(::MethodTable) at reflection.jl:746
│      ...
│    Stacktrace:
│     [1] show_method_candidates(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::MethodError, ::Any) at ./replutil.jl:551
│

This is the code that got called, which had gotten a method error:

@propagate_inbounds isvalid(s::AbstractString, i::Integer) = typeof(i) === Int ?
    throw(MethodError(isvalid, Tuple{typeof(s),Int})) : isvalid(s, Int(i))

and the error that caused the failure was this:

  MethodError: no method matching isvalid(::UTF16Str, ::Int64)
  Stacktrace:
   [1] isvalid at ./strings/basic.jl:121 [inlined]
   [2] SubString{UTF16Str}(::UTF16Str, ::Int64, ::Int64) at ./strings/substring.jl:31

This was all on master, v"0.7.0-DEV.3323"


#2

Looks like the code throwing the error has a typo, and should be:

throw(MethodError(isvalid, (s, i)))

#3

There are a number of places there that all have Tuple{typeof(s),Int}, so I suppose they all would need to get fixed. Is this just some really old syntax from before my time that wasn’t updated, or these methods don’t have unit tests that check that the error case works?


#4

AFAICT there are three occurrences which are all in the same file, so I’d say it’s just an oversight. @StefanKarpinski must know.


#5

Please open an issue and I’ll take a look.