In the middle of reading another question, I used Cthulhu.jl to @descend
into maximum([1,2,3])
to find an internal method to pirate, but contrary to my intentions, it didn’t break anything:
julia> @eval Base mapreduce_first(::typeof(identity), ::typeof(max), ::Int) = throw(ErrorException("piracy!"))
mapreduce_first (generic function with 2 methods)
julia> maximum([1, 2, 3]) # still works?!
3
@descend
ing into maximum([1,2,3])
confirms that it should’ve called the piracy method
...
• %31 = mapreduce_first(::typeof(identity),::typeof(max),::Int64)::Union{}
...
• %2 = < concrete eval > ErrorException(::Core.Const("piracy!"))::Core.Const(ErrorException("piracy!"))
...
Why wasn’t maximum(::Vector{Int64})
invalidated and recompiled to use the pirated method? It works/breaks if I pirate something closer:
julia> @eval Base _maximum(a::Vector{Int64}, ::Colon; kw...) = throw(ErrorException("piracy!"))
_maximum (generic function with 5 methods)
julia> maximum([1,2,3])
ERROR: piracy!