Skip to content

Commit 9a343be

Browse files
fix: fix stack overflow when converting Term to non-concrete coefficient type (#332)
* fix: fix stack overflow when `convert`ing `Term` to non-concrete coefficient type * fix: fix conversion to identically typed `Term`
1 parent 8a641bc commit 9a343be

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/default_term.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ 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+
function Base.convert(::Type{Term{T,M}}, t::Term{T,M}) where {T,M}
38+
return t
39+
end
40+
3441
function convert_constant(::Type{Term{C,M} where C}, α) where {M}
3542
return convert(Term{typeof(α),M}, α)
3643
end

test/commutative/term.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ 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
68+
MP.Term{Number,MP.monomial_type(t)}
69+
6670
@testset "Effective variables" begin
6771
T = variable_union_type(x)
6872
@test x isa T

0 commit comments

Comments
 (0)