Skip to content

Commit fea2000

Browse files
committed
as noted in the commentary on #11840, there existed a similar issue for inserting/matching Type{T} in the gf cache
1 parent 139f888 commit fea2000

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/gf.c

+16-8
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,22 @@ static jl_function_t *cache_method(jl_methtable_t *mt, jl_tupletype_t *type,
537537
}
538538
if (set_to_any || isstaged) {
539539
}
540+
else if (jl_is_type_type(elt) && jl_is_typector(jl_tparam0(elt)) &&
541+
decl_i == (jl_value_t*)jl_typector_type) {
542+
// TypeConstructors are problematic because they can be alternate
543+
// representations of any type. If we matched this method because
544+
// it matched the leaf type TypeConstructor, then don't
545+
// cache something different since that doesn't necessarily actually apply
546+
jl_svecset(newparams, i, jl_typector_type);
547+
}
548+
else if (jl_is_type_type(elt) && decl_i == (jl_value_t*)jl_datatype_type) {
549+
// similarly, if we matched Type{T<:Any}::DataType,
550+
// then we don't want to cache it that way
551+
// since lookup will think we matched ::Type{T}
552+
// and that is quite a different thing
553+
jl_svecset(newparams, i, jl_datatype_type);
554+
need_guard_entries = 1; // DataType has a UID so its precedence in the cache may be too high
555+
}
540556
else if (jl_is_type_type(elt) && jl_is_type_type(jl_tparam0(elt)) &&
541557
// give up on specializing static parameters for Type{Type{Type{...}}}
542558
(jl_is_type_type(jl_tparam0(jl_tparam0(elt))) ||
@@ -568,14 +584,6 @@ static jl_function_t *cache_method(jl_methtable_t *mt, jl_tupletype_t *type,
568584
need_guard_entries = 1;
569585
assert(jl_svecref(newparams,i) != (jl_value_t*)jl_bottom_type);
570586
}
571-
else if (jl_is_type_type(elt) && jl_is_typector(jl_tparam0(elt)) &&
572-
decl_i == (jl_value_t*)jl_typector_type) {
573-
// TypeConstructors are problematic because they can be alternate
574-
// representations of any type. If we matched this method because
575-
// it matched the leaf type TypeConstructor, then don't
576-
// cache something different since that doesn't necessarily actually apply
577-
jl_svecset(newparams, i, jl_typector_type);
578-
}
579587
else if (jl_is_type_type(elt) && very_general_type(decl_i) &&
580588
!jl_has_typevars(decl_i)) {
581589
/*

0 commit comments

Comments
 (0)