LinearAlgebra.jl icon indicating copy to clipboard operation
LinearAlgebra.jl copied to clipboard

Identical method signatures sometimes counted as different, leading to ambiguities

Open KristofferC opened this issue 3 years ago • 1 comments

When loading an external copy of LinearAlgebra (as in the tests for https://github.com/JuliaLang/LinearAlgebra.jl) there are some new method ambiguities that arises, even if the external copy should have the exact same methods defined and thereby just overwrite the original methods (https://github.com/JuliaLang/LinearAlgebra.jl/runs/8190014866?check_suite_focus=true). In the log, there are some differences in the signatures due the gensym generation for the {<: BlasReal} syntax but that is not the cause of this. Applying the patch:

diff --git a/stdlib/LinearAlgebra/src/matmul.jl b/stdlib/LinearAlgebra/src/matmul.jl
index 2216d1858d..e15583b637 100644
--- a/stdlib/LinearAlgebra/src/matmul.jl
+++ b/stdlib/LinearAlgebra/src/matmul.jl
@@ -143,7 +143,7 @@ end
-function (*)(A::StridedMaybeAdjOrTransMat{<:BlasReal}, B::StridedMaybeAdjOrTransMat{<:BlasReal})
+function (*)(A::StridedMaybeAdjOrTransMat{T1}, B::StridedMaybeAdjOrTransMat{T2}) where {T1 <: BlasReal, T2 <: BlasReal}
     TS = promote_type(eltype(A), eltype(B))
     mul!(similar(B, TS, (size(A, 1), size(B, 2))),
          wrapperop(A)(convert(AbstractArray{TS}, _parent(A))),

the error message is instead

Candidates:
  *(A::Union{Adjoint{T1, <:StridedMatrix{T} where T}, Transpose{T1, <:StridedMatrix{T} where T}, StridedMatrix{T1}}, B::Union{Adjoint{T2, <:StridedMatrix{T} where T}, Transpose{T2, <:StridedMatrix{T} where T}, StridedMatrix{T2}}) where {T1<:Union{Float32, Float64}, T2<:Union{Float32, Float64}}
    @ LinearAlgebra ~/julia/usr/share/julia/stdlib/v1.9/LinearAlgebra/src/matmul.jl:146
  *(A::Union{Adjoint{T1, <:StridedMatrix{T} where T}, Transpose{T1, <:StridedMatrix{T} where T}, StridedMatrix{T1}}, B::Union{Adjoint{T2, <:StridedMatrix{T} where T}, Transpose{T2, <:StridedMatrix{T} where T}, StridedMatrix{T2}}) where {T1<:Union{Float32, Float64}, T2<:Union{Float32, Float64}}
    @ LinearAlgebra ~/LinearAlgebra.jl/src/matmul.jl:146
To resolve the ambiguity, try making one of the methods more specific, or adding a new method more specific than any of the existing applicable methods.

where the signatures are in fact identical. Ideally, the method from the sysimage LinearAlgebra would be overwritten by the externally loaded one so there would be no ambiguity.

KristofferC avatar Sep 07 '22 10:09 KristofferC