Currently, x^2
is lowered to Base.literal_pow(^, x, ::Val{2})
. If no method is defined for this, it calls ^(x,2)
. This seems to imply that packages should specialize Base.literal_pow
for custom types, but they shouldn’t do this if the function is internal to Base
. This is not a huge issue if one only wants ^(x,p)
and doesn’t care about special values of p
.
However, if one wishes to specialize x .^ 2
for a custom AbstractArray
x
without implementing a broadcast style, they apparently need to specialize broadcasted(::typeof(Base.literal_pow), arg1::Base.RefValue{typeof(^)}, x, ::Base.RefValue{Val{2}})
. This requires dispatching on Base.literal_pow
, which one shouldn’t if Base.literal_pow
is internal to Base
(same with Base.RefValue
, in this case). Moreover, this doesn’t call Base.broadcasted(::DefaultArrayStyle, ::typeof(^), x, 2)
by default, so there’s no workaround available, unlike the non-broadcast version. (Arguably, such a method may be added.)
The function is used by a reasonably large number of packages already, so it might make some sense to declare this to be public.