Here’s a weird one:
struct Testype x::Int64 end import Base.broadcast Base.broadcast(::typeof(*), t1::Testype, t2::Testype) = (t1.x * t2.x) t1 = Testype(2) t2 = Testype(3)
Now, if you do
t1 .* t2 everything is fine. However, if you do
t1 .* t1 you get
ERROR: MethodError: no method matching *(::Testype, ::Testype) Closest candidates are: *(::Any, ::Any, ::Any, ::Any...) at operators.jl:424 Stacktrace:  (::##3#4)(::Testype) at ./<missing>:0  broadcast(::Function, ::Testype) at ./broadcast.jl:434
It appears that the call to
broadcast(*, ...) falls back to the
Base definition only in cases where a repeated argument is given.
Why? How do I circumvent this?
I suppose this might be some special behavior to handle squaring more efficiently, but it’s not exactly transparent to the user how this is being done or what methods he should extend to fix it.