Skip to content

Commit f6f496e

Browse files
fix: fix stack overflow when converting Term to non-concrete coefficient type
1 parent 9df2c20 commit f6f496e

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/conversion.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ function Base.convert(TT::Type{<:AbstractTerm{T}}, t::AbstractTerm) where {T}
5858
),
5959
)
6060
end
61+
function Base.convert(::Type{Term{T, M}}, t::AbstractTerm) where {T, M}
62+
return Term{T, M}(convert(T, coefficient(t)), convert(M, monomial(t)))
63+
end
6164

6265
# Base.convert(::Type{T}, t::T) where {T <: AbstractTerm} is ambiguous with above method.
6366
# we need the following:

test/commutative/term.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ MP.term_type(::Type{Term2{T,M}}) where {T,M} = MP.Term{T,M}
6363
@test_throws InexactError push!([1], 2x)
6464
@test_throws InexactError push!([x^2], 2x)
6565

66+
t = MP.term(1, x)
67+
@test convert(MP.Term{Number, MP.monomial_type(t)}, t) isa MP.Term{Number, MP.monomial_type(t)}
68+
6669
@testset "Effective variables" begin
6770
T = variable_union_type(x)
6871
@test x isa T

0 commit comments

Comments
 (0)