Even more clarification on Type piracy

Minimal example of how to ruin someone’s day with type-piracy.

julia> module A
       Base.:*(a::Float64,b::Float64) = 4
       end
WARNING: Method definition *(Float64, Float64) in module Base at float.jl:379 overwritten in module A at REPL[1]:2.
A

julia> module B
       using A
       end
B

julia> using B

julia> a = 1.0
1.0

julia> b = 2.0
2.0

julia> a*b
4

Now go bury that in somewhere and find out how long it takes for someone to take that WARNING seriously. Note that if you make a definition which doesn’t actually exist with Base types on a Base function, it will do the same thing without a warning. That’s why it’s not allowed.

Necessary: “with great power comes great responsibility.”

3 Likes