Skip to content

Commit c67c523

Browse files
authored
Merge pull request #22701 from JuliaLang/jb/Type_right_rule
fix and simplify subtyping rule for `x <: Type{T}`
2 parents 0c9a858 + f0e3678 commit c67c523

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

src/subtype.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -883,21 +883,9 @@ static int subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int param)
883883
}
884884
if (jl_is_type_type(y) && !jl_is_type_type(x) && x != (jl_value_t*)jl_typeofbottom_type) {
885885
jl_value_t *tp0 = jl_tparam0(yd);
886-
if (!jl_is_typevar(tp0))
886+
if (!jl_is_typevar(tp0) || !jl_is_kind(x))
887887
return 0;
888-
if (!jl_is_kind(x)) return 0;
889-
jl_varbinding_t *yy = lookup(e, (jl_tvar_t*)tp0);
890-
jl_value_t *ub = yy ? yy->ub : ((jl_tvar_t*)tp0)->ub;
891-
int ans;
892-
if (ub == (jl_value_t*)jl_any_type) {
893-
ans = subtype((jl_value_t*)jl_type_type, y, e, param);
894-
}
895-
else {
896-
e->invdepth++;
897-
ans = forall_exists_equal(x, tp0, e);
898-
e->invdepth--;
899-
}
900-
return ans;
888+
return subtype((jl_value_t*)jl_type_type, y, e, param);
901889
}
902890
while (xd != jl_any_type && xd->name != yd->name) {
903891
if (xd->super == NULL)

test/subtype.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,9 @@ function test_Type()
446446
@test isa(Int, @UnionAll T<:Number Type{T})
447447
@test !isa(DataType, @UnionAll T<:Number Type{T})
448448

449-
@test DataType <: (@UnionAll T<:Type Type{T})
449+
@test !(DataType <: (@UnionAll T<:Type Type{T}))
450+
@test isa(DataType, (@UnionAll T<:Type Type{T}))
451+
450452
@test isa(Tuple{},Type{Tuple{}})
451453
@test !(Tuple{Int,} <: (@UnionAll T<:Tuple Type{T}))
452454
@test isa(Tuple{Int}, (@UnionAll T<:Tuple Type{T}))

0 commit comments

Comments
 (0)