`Base.max(::Int, ::Int) = nothing` crashes Julia

I did Base.max(::Int, ::Int) = nothing and it crashed Julia. Is this expected behavior or should it be reported?

This is a potential consequence of committing type piracy - you’ve ended up overwriting a method that’s used by julia internally, causing an error that’s fatal. You get a similar result if you redefine Base.+(::Int, ::Int). The crash here is expected.

8 Likes

It’s also documented in the style guide that type piracy “can crash Julia”.

4 Likes

What are you trying to do?

Just trying to understand what’s going on. I’m happ with “piracy can crash” as a answer. I was guessing that Julia was using the function internally. So good to have that confirmed. Thanks.

Why would you ever want to do this, though?

1 Like

I don’t want to, at least not with max. I was just fooling around. I found it surprising that Julia crashed as soon as I defined it, without me even calling it, which is what prompted this post. That does not happen with, say, Base.read(::String) = true.

It depends on what code is used by the REPL and the runtime. You can think of it as sawing off a random branch from a tree. If you happen to be sitting on it you crash.

8 Likes