Skip to content

Commit 2cdc417

Browse files
authored
make the default constructor type stable (#389)
1 parent c30d0a5 commit 2cdc417

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/abstract.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ macro register(name)
8383
Base.promote_rule(::Type{<:$poly{T,X}}, ::Type{<:$poly{S,X}}) where {T,S,X} = $poly{promote_type(T, S),X}
8484
Base.promote_rule(::Type{<:$poly{T,X}}, ::Type{S}) where {T,S<:Number,X} =
8585
$poly{promote_type(T, S),X}
86-
$poly(coeffs::AbstractVector{T}, var::SymbolLike = :x) where {T} =
86+
$poly(coeffs::AbstractVector{T}) where {T} =
87+
$poly{T, :x}(coeffs)
88+
$poly(coeffs::AbstractVector{T}, var::SymbolLike) where {T} =
8789
$poly{T, Symbol(var)}(coeffs)
8890
$poly{T}(x::AbstractVector{S}, var::SymbolLike = :x) where {T,S} =
8991
$poly{T,Symbol(var)}(T.(x))

test/StandardBasis.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ end
393393
pN = P([276,3,87,15,24,0])
394394
pR = P([3 // 4, -2 // 1, 1 // 1])
395395

396+
# type stability of the default constructor without variable name
397+
if P !== ImmutablePolynomial
398+
@inferred P([1, 2, 3])
399+
end
396400

397401
@test p3 == P([1,2,1])
398402
@test pN * 10 == P([2760, 30, 870, 150, 240])

0 commit comments

Comments
 (0)