Skip to content

Commit d61356e

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

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/default_term.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ monomial_type(::Type{<:Term{C,M}}) where {C,M} = M
3131
function Base.convert(::Type{Term{T,M}}, m::AbstractMonomialLike) where {T,M}
3232
return Term(one(T), convert(M, m))
3333
end
34+
function Base.convert(::Type{Term{T, M}}, t::AbstractTerm) where {T, M}
35+
return Term{T, M}(convert(T, coefficient(t)), convert(M, monomial(t)))
36+
end
37+
3438
function convert_constant(::Type{Term{C,M} where C}, α) where {M}
3539
return convert(Term{typeof(α),M}, α)
3640
end

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)