Skip to content

Commit e40f120

Browse files
committed
More robust promote_operation for *
1 parent 75ace1f commit e40f120

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/promote.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ function MA.promote_operation(::typeof(*), TT::Type{<:AbstractTermLike{S}},
5959
U = MA.promote_operation(*, S, T)
6060
return termtype(promote_type(monomialtype(TT), monomialtype(ST)), U)
6161
end
62-
function MA.promote_operation(::typeof(*), PT::Type{<:APL{S}},
63-
QT::Type{<:APL{T}}) where {S, T}
64-
U = MA.promote_operation(MA.add_mul, S, T)
62+
function MA.promote_operation(::typeof(*), PT::Type{<:APL{S}}, QT::Type{<:APL{T}}) where {S, T}
63+
ST = MA.promote_operation(*, S, T)
64+
U = MA.promote_operation(+, ST, ST)
6565
return polynomialtype(promote_type(monomialtype(PT), monomialtype(QT)), U)
6666
end

test/promote.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,18 @@
2323
@test Y[2] == 2x + 4y
2424
@test dot(X, [1 2; 3 4] * X) == x^2 + 5x*y + 4y^2
2525
end
26+
27+
struct A end
28+
Base.zero(::Type{A}) = A()
29+
Base.:*(::A, ::A) = B()
30+
struct B end
31+
Base.zero(::Type{B}) = B()
32+
Base.:+(::B, ::B) = C()
33+
struct C end
34+
Base.:+(::B, ::C) = C()
35+
Base.:+(::C, ::B) = C()
36+
Base.:+(::C, ::C) = C()
37+
@testset "promote_operation with tricky types" begin
38+
Mod.@polyvar x
39+
@test MA.promote_operation(*, polynomialtype(x, A), polynomialtype(x, A)) == polynomialtype(x, C)
40+
end

0 commit comments

Comments
 (0)