-
-
Notifications
You must be signed in to change notification settings - Fork 35
Description
I don't have a minimal reproducing example at the moment, since this arose in private code, but consider the following situation: Say you have a Matrix{Float64} called A and a Vector{K} called x, where K is an abstract type. Various operations such as + and * are defined for K to return specific subtypes. The subtypes do not convert between each other. A * x should work; all of the necessary operations are defined.
With Julia 1.0, we get a Vector{Any} from A * x. Not ideal but fine. On 1.1, we get an error, saying it can't convert x's elements to a certain type. The issue seems to boil down to this difference:
On 1.0:
julia> Base.promote_op(LinearAlgebra.matprod, Float64, K)
Any
1.1:
julia> map(eltype, x)
3-element Array{DataType,1}:
K0
K4
K0
julia> Base.promote_op(LinearAlgebra.matprod, Float64, K)
Union{K1, K2, K3}
LinearAlgebra then tries to do convert(AbstractArray{Union{K1, K2, K3}, x), which fails, since it can't convert x's elements to that type.
As of JuliaLang/julia#29739, promote_op is just a wrapper atop _return_type, which is returning the correct answer, but is not appropriate for this use.