From 484ce822c4ef0d3cccf083ce5aa3b98cf5e30c5d Mon Sep 17 00:00:00 2001 From: N5N3 <2642243996@qq.com> Date: Wed, 11 Jan 2023 15:10:47 +0800 Subject: [PATCH] Disallow more circulation once we set `lb`==`ub`. close #26487. This should be valid as we never set `X<:Y<:X` (assuming `Y` is the outer var). --- src/subtype.c | 10 +++++++++- test/subtype.jl | 8 +++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/subtype.c b/src/subtype.c index 59055e6bc168e..8189e9701e452 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -3249,7 +3249,15 @@ static jl_value_t *intersect(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int pa return jl_bottom_type; } int ccheck; - if (yub == xub || + if (xlb == xub && ylb == yub && + jl_has_typevar(xlb, (jl_tvar_t *)y) && + jl_has_typevar(ylb, (jl_tvar_t *)x)) { + // specical case for e.g. + // 1) Val{Y}<:X<:Val{Y} && Val{X}<:Y<:Val{X} + // 2) Y<:X<:Y && Val{X}<:Y<:Val{X} => Val{Y}<:Y<:Val{Y} + ccheck = 0; + } + else if (yub == xub || (subtype_by_bounds(xlb, yub, e) && subtype_by_bounds(ylb, xub, e))) { ccheck = 1; } diff --git a/test/subtype.jl b/test/subtype.jl index 3517e8fdc906c..7236d3438a692 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -2357,6 +2357,11 @@ end Tuple{Type{Vector{Union{T, R}}}, Matrix{Union{T, R}}} where {R<:Real, T<:Real}, Union{}) +#issue 26487 +@testintersect(Tuple{Type{Tuple{T,Val{T}}}, Val{T}} where T, + Tuple{Type{Tuple{Val{T},T}}, Val{T}} where T, + Union{}) + @testset "known subtype/intersect issue" begin #issue 45874 # Causes a hang due to jl_critical_error calling back into malloc... @@ -2384,9 +2389,6 @@ end #issue 33137 @test_broken (Tuple{Q,Int} where Q<:Int) <: Tuple{T,T} where T - #issue 26487 - @test_broken typeintersect(Tuple{Type{Tuple{T,Val{T}}}, Val{T}} where T, Tuple{Type{Tuple{Val{T},T}}, Val{T}} where T) <: Any - # issue 24333 @test_broken (Type{Union{Ref,Cvoid}} <: Type{Union{T,Cvoid}} where T)