From a9fa0cb0a1fa4410ab989f9eb820f455e09be262 Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Thu, 5 Dec 2024 16:27:05 +0000 Subject: [PATCH 1/2] Avoid StackOverflow in promote_type with Any --- src/promote.jl | 7 +++++++ test/Project.toml | 2 +- test/promote.jl | 6 ++++++ test/test/Project.toml | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/test/Project.toml diff --git a/src/promote.jl b/src/promote.jl index 1302fffc..86399003 100644 --- a/src/promote.jl +++ b/src/promote.jl @@ -24,6 +24,13 @@ function promote_rule_constant( return term_type(TT, promote_type(S, T)) end +function promote_rule_constant( + ::Type{Any}, + TT::Type{<:AbstractTermLike{T}}, +) where {T} + return Any +end + # PolynomialLike Base.promote_rule(::Type{PT}, ::Type{PT}) where {PT<:_APL} = PT function Base.promote_rule(PS::Type{<:_APL}, PT::Type{<:_APL}) diff --git a/test/Project.toml b/test/Project.toml index 46cf9f3e..0b8e8bd0 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -10,5 +10,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" TypedPolynomials = "afbbf031-7a57-5f58-a1b9-b774a0fad08d" [compat] -DynamicPolynomials = "0.5" +DynamicPolynomials = "0.5, 0.6.2" TypedPolynomials = "0.4" diff --git a/test/promote.jl b/test/promote.jl index 743f2052..b020efd4 100644 --- a/test/promote.jl +++ b/test/promote.jl @@ -171,3 +171,9 @@ end __promote_prod(PXY, PXY, PXY) end end + +@testset "promote_operation with Any" begin + Mod.@polyvar x + V = typeof(x) + @test promote_type(V, Any) == Any +end \ No newline at end of file diff --git a/test/test/Project.toml b/test/test/Project.toml new file mode 100644 index 00000000..81648c0b --- /dev/null +++ b/test/test/Project.toml @@ -0,0 +1 @@ +[deps] From 766e6b24fab3c0413ad9951f9e3382ce55c73d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Thu, 5 Dec 2024 22:01:30 +0100 Subject: [PATCH 2/2] Update src/promote.jl --- src/promote.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/promote.jl b/src/promote.jl index 86399003..a6701057 100644 --- a/src/promote.jl +++ b/src/promote.jl @@ -26,7 +26,7 @@ end function promote_rule_constant( ::Type{Any}, - TT::Type{<:AbstractTermLike{T}}, + ::Type{<:AbstractTermLike{T}}, ) where {T} return Any end