Skip to content

Commit 6fb2c67

Browse files
committed
fix #20998
This was a case where an unknown typevar was incorrectly inferred to have the value `Any`.
1 parent b626d0b commit 6fb2c67

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/subtype.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,9 +1286,9 @@ static jl_value_t *finish_unionall(jl_value_t *res, jl_varbinding_t *vb, jl_sten
12861286

12871287
if (vb->right && e->envidx < e->envsz) {
12881288
jl_value_t *oldval = e->envout[e->envidx];
1289-
if (!varval)
1289+
if (!varval || (!is_leaf_bound(varval) && !var_occurs_invariant(res, vb->var, 0)))
12901290
e->envout[e->envidx] = (jl_value_t*)vb->var;
1291-
else if (!oldval || !jl_is_typevar(oldval) || !jl_is_long(varval))
1291+
else if (!(oldval && jl_is_typevar(oldval) && jl_is_long(varval)))
12921292
e->envout[e->envidx] = varval;
12931293
}
12941294

test/subtype.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,10 @@ function test_intersection()
853853
@testintersect(Tuple{Ref{Pair{p2,T2}}, Pair{p1,Pair}} where T2 where p2 where p1,
854854
Tuple{Ref{Pair{p3,T3}}, Pair{p3}} where T3 where p3,
855855
Tuple{Ref{Pair{p1,T2}}, Pair{p1,Pair}} where T2 where p1)
856+
857+
# issue #20998
858+
_, E = intersection_env(Tuple{Int,Any,Any}, Tuple{T,T,S} where {T,S})
859+
@test length(E) == 2 && E[1] == Int && isa(E[2], TypeVar)
856860
end
857861

858862
function test_intersection_properties()

0 commit comments

Comments
 (0)