Skip to content

Commit c90e917

Browse files
authored
Merge pull request #101 from JuliaAlgebra/bl/convert
Avoid defining conversion to Any
2 parents 53f7143 + 90fb283 commit c90e917

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/conversion.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Base.convert(::Type{P}, p::APL) where P<:AbstractPolynomial = P(polynomial(p))
66

77
Base.convert(::Type{Any}, p::APL) = p
88
# Conversion polynomial -> scalar
9-
function Base.convert(::Type{S}, p::APL) where {S}
9+
function Base.convert(S::Type{<:Union{Number, T}}, p::APL{T}) where T
1010
s = zero(S)
1111
for t in terms(p)
1212
if !isconstant(t)

test/polynomial.jl

+7
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,11 @@ const MP = MultivariatePolynomials
133133
@test coefficients(f) == [7, 4, -5, 4]
134134
@test monomials(f) == monovec([x^2*z^2, x*y^2*z, x^3, z^2])
135135
end
136+
137+
@testset "Convertion" begin
138+
p = 2.5x + 1 - 2.5x
139+
@test convert(Int, p) == 1
140+
@test convert(typeof(p), p) === p
141+
@test convert(Union{Nothing, typeof(p)}, p) === p
142+
end
136143
end

0 commit comments

Comments
 (0)