Overwriting Methods

Is there a way to tell when you are overwriting a method?

For example:
The following code exists:

f(x::Int) = 0

And then this exists somewhere later:

f(x::Int) = 1

Is there a way to make the second line of code error?

You can start with --warn-overwrite but I don’t think there is a way right now to make it error

$ julia --warn-overwrite=yes -q
julia> f(x::Int) = 0
f (generic function with 1 method)

julia> f(x::Int) = 1
WARNING: Method definition f(Int64) in module Main at REPL[1]:1 overwritten at REPL[2]:1.
f (generic function with 1 method)
4 Likes

Thanks! A warning is good enough. I was dealing with a bug where this would have helped weed out the error faster. I’ll keep it handy for next time.