Skip to content

Commit 02f37d8

Browse files
committed
Disallow more circulation once we set lb==ub.
close #26487. This should be valid as we never set `X<:Y<:X` (assuming `Y` is outer var).
1 parent 46b6c9a commit 02f37d8

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/subtype.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3249,7 +3249,13 @@ static jl_value_t *intersect(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int pa
32493249
return jl_bottom_type;
32503250
}
32513251
int ccheck;
3252-
if (yub == xub ||
3252+
if (xlb == xub && ylb == yub && jl_has_typevar(xlb, y) && jl_has_typevar(ylb, x)) {
3253+
// specical case for e.g.
3254+
// 1) Val{Y}<:X<:Val{Y} && Val{X}<:Y<:Val{X}
3255+
// 2) Y<:X<:Y && Val{X}<:Y<:Val{X} => Val{Y}<:Y<:Val{Y}
3256+
ccheck = 0;
3257+
}
3258+
else if (yub == xub ||
32533259
(subtype_by_bounds(xlb, yub, e) && subtype_by_bounds(ylb, xub, e))) {
32543260
ccheck = 1;
32553261
}

test/subtype.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,6 +2357,11 @@ end
23572357
Tuple{Type{Vector{Union{T, R}}}, Matrix{Union{T, R}}} where {R<:Real, T<:Real},
23582358
Union{})
23592359

2360+
#issue 26487
2361+
@testintersect(Tuple{Type{Tuple{T,Val{T}}}, Val{T}} where T,
2362+
Tuple{Type{Tuple{Val{T},T}}, Val{T}} where T,
2363+
Union{})
2364+
23602365
@testset "known subtype/intersect issue" begin
23612366
#issue 45874
23622367
# Causes a hang due to jl_critical_error calling back into malloc...
@@ -2384,9 +2389,6 @@ end
23842389
#issue 33137
23852390
@test_broken (Tuple{Q,Int} where Q<:Int) <: Tuple{T,T} where T
23862391

2387-
#issue 26487
2388-
@test_broken typeintersect(Tuple{Type{Tuple{T,Val{T}}}, Val{T}} where T, Tuple{Type{Tuple{Val{T},T}}, Val{T}} where T) <: Any
2389-
23902392
# issue 24333
23912393
@test_broken (Type{Union{Ref,Cvoid}} <: Type{Union{T,Cvoid}} where T)
23922394

0 commit comments

Comments
 (0)