Why isn't this Base piracy breaking a Base method call?

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

@descending 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!

You need to call something that ends up calling the pirated method, for example:

julia> @eval Base mapreduce_first(::typeof(identity), ::typeof(max), ::Int) = throw(ErrorException("piracy!"))
mapreduce_first (generic function with 2 methods)

julia> maximum([1])
ERROR: piracy!
Stacktrace:
1 Like

Thanks for pointing that out, I wasn’t paying enough attention to the source code so I pirated something in the wrong branch for the given input.