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

**URL:** <https://discourse.julialang.org/t/why-isnt-this-base-piracy-breaking-a-base-method-call/122894>\
**Category:** Internals & Design\
**Tags:** type-piracy\
**Created:** [November 21, 2024, 12:31pm UTC](https://discourse.julialang.org/t/why-isnt-this-base-piracy-breaking-a-base-method-call/122894 "2024-11-21T12:31:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [November 21, 2024, 12:31pm UTC](https://discourse.julialang.org/t/why-isnt-this-base-piracy-breaking-a-base-method-call/122894/1 "2024-11-21T12:31:21Z")

</div>

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
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

```julia
...
 • %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
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!

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 21, 2024, 12:49pm UTC](https://discourse.julialang.org/t/why-isnt-this-base-piracy-breaking-a-base-method-call/122894/2 "2024-11-21T12:49:43Z")

</div>

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

```julia
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:

```

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [November 21, 2024, 1:03pm UTC](https://discourse.julialang.org/t/why-isnt-this-base-piracy-breaking-a-base-method-call/122894/3 "2024-11-21T13:03:25Z")

</div>

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.
