Skip to content

Commit b20b599

Browse files
committed
fix #50709, type bound error due to free typevar in sparam env
1 parent 3c18223 commit b20b599

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/subtype.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4167,6 +4167,34 @@ static int might_intersect_concrete(jl_value_t *a)
41674167
return 0;
41684168
}
41694169

4170+
static jl_value_t *widen_sparam_bound(jl_value_t *t)
4171+
{
4172+
if (!jl_has_free_typevars(t))
4173+
return t;
4174+
if (jl_is_datatype(t))
4175+
return ((jl_datatype_t*)t)->name->wrapper;
4176+
return (jl_value_t*)jl_any_type;
4177+
}
4178+
4179+
static jl_value_t *narrow_sparam_bound(jl_value_t *t)
4180+
{
4181+
if (!jl_has_free_typevars(t))
4182+
return t;
4183+
return jl_bottom_type;
4184+
}
4185+
4186+
static jl_value_t *widen_sparam_estimate(jl_value_t *t)
4187+
{
4188+
if (!jl_is_typevar(t))
4189+
return t;
4190+
jl_tvar_t *v = (jl_tvar_t*)t;
4191+
jl_value_t *wlb = narrow_sparam_bound(v->lb);
4192+
jl_value_t *wub = widen_sparam_bound(v->ub);
4193+
if (wlb != v->lb || wub != v->ub)
4194+
return (jl_value_t*)jl_new_typevar(v->name, wlb, wub);
4195+
return t;
4196+
}
4197+
41704198
// sets *issubty to 1 iff `a` is a subtype of `b`
41714199
jl_value_t *jl_type_intersection_env_s(jl_value_t *a, jl_value_t *b, jl_svec_t **penv, int *issubty)
41724200
{
@@ -4251,7 +4279,7 @@ jl_value_t *jl_type_intersection_env_s(jl_value_t *a, jl_value_t *b, jl_svec_t *
42514279
jl_svec_t *e = jl_alloc_svec(sz);
42524280
for (i = 0; i < sz; i++) {
42534281
assert(env[i]);
4254-
jl_svecset(e, i, env[i]);
4282+
jl_svecset(e, i, widen_sparam_estimate(env[i]));
42554283
}
42564284
*penv = e;
42574285
}

test/subtype.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,3 +2565,9 @@ let a = Tuple{Union{Nothing, Type{Pair{T1}} where T1}}
25652565
b = Tuple{Type{X2} where X2<:(Pair{T2, Y2} where {Src, Z2<:Src, Y2<:Union{Val{Z2}, Z2}})} where T2
25662566
@test !Base.has_free_typevars(typeintersect(a, b))
25672567
end
2568+
2569+
# issue #50709
2570+
let (t, (tv,)) = intersection_env(Type{Vector{S}} where {T, S<:AbstractVector{T}}, Type{Vector{T}} where T)
2571+
@test tv isa TypeVar
2572+
@test !Base.has_free_typevars(tv.ub)
2573+
end

0 commit comments

Comments
 (0)