From 1a1bfed7b9bbb8521aa63afb782cbccdc79fdc32 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 4 Apr 2026 06:55:58 +0000 Subject: [PATCH] Fix StackOverflowError in promote_type with Any (#94, #166) Return Union{} instead of Any from promote_rule_constant when the coefficient type is unspecified. Returning Any causes infinite recursion in Base.promote_type because promote_rule returns Any from one direction and the polynomial type from the other. This fixes the StackOverflowError that occurs when Julia 1.13's @test macro evaluates function arguments and creates Expr-typed values that trigger type promotion with polynomial types. https://claude.ai/code/session_01SGAgzkbRVNAL51y3Fo9fni --- src/promote.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/promote.jl b/src/promote.jl index f739611..e8bda0b 100644 --- a/src/promote.jl +++ b/src/promote.jl @@ -60,8 +60,8 @@ function MP.promote_rule_constant( ) where {S,V,M,T} return Polynomial{V,M,promote_type(S, T)} end -MP.promote_rule_constant(::Type, ::Type{_Term{V,M}}) where {V,M} = Any -MP.promote_rule_constant(::Type, ::Type{Polynomial{V,M}}) where {V,M} = Any +MP.promote_rule_constant(::Type, ::Type{_Term{V,M}}) where {V,M} = Union{} +MP.promote_rule_constant(::Type, ::Type{Polynomial{V,M}}) where {V,M} = Union{} function Base.promote_rule( ::Type{_Term{V,M}}, ::Type{_Term{V,M,T}},