@@ -4904,7 +4904,7 @@ findGenericParameterReferencesRec(CanGenericSignature genericSig,
4904
4904
TypePosition position,
4905
4905
bool canBeCovariantResult) {
4906
4906
// If there are no type parameters, we're done.
4907
- if (!type->hasTypeParameter ())
4907
+ if (!type->getCanonicalType ()-> hasTypeParameter ())
4908
4908
return GenericParameterReferenceInfo ();
4909
4909
4910
4910
// Tuples preserve variance.
@@ -4954,7 +4954,7 @@ findGenericParameterReferencesRec(CanGenericSignature genericSig,
4954
4954
// Don't forget to look in the parent.
4955
4955
if (const auto parent = nominal->getParent ()) {
4956
4956
info |= findGenericParameterReferencesRec (
4957
- genericSig, genericParam, parent, position ,
4957
+ genericSig, genericParam, parent, TypePosition::Invariant ,
4958
4958
/* canBeCovariantResult=*/ false );
4959
4959
}
4960
4960
@@ -5033,10 +5033,40 @@ findGenericParameterReferencesRec(CanGenericSignature genericSig,
5033
5033
return info;
5034
5034
}
5035
5035
5036
- if (!type->isTypeParameter ()) {
5036
+ // Packs are invariant.
5037
+ if (auto *pack = type->getAs <PackType>()) {
5038
+ auto info = GenericParameterReferenceInfo ();
5039
+
5040
+ for (auto arg : pack->getElementTypes ()) {
5041
+ info |= findGenericParameterReferencesRec (
5042
+ genericSig, genericParam, arg,
5043
+ TypePosition::Invariant, /* canBeCovariantResult=*/ false );
5044
+ }
5045
+
5046
+ return info;
5047
+ }
5048
+
5049
+ // Pack expansions are invariant.
5050
+ if (auto *expansion = type->getAs <PackExpansionType>()) {
5051
+ return findGenericParameterReferencesRec (
5052
+ genericSig, genericParam, expansion->getPatternType (),
5053
+ TypePosition::Invariant, /* canBeCovariantResult=*/ false );
5054
+ }
5055
+
5056
+ // Specifically ignore parameterized protocols and existential
5057
+ // metatypes because we can erase them to the upper bound.
5058
+ if (type->is <ParameterizedProtocolType>() ||
5059
+ type->is <ExistentialMetatypeType>()) {
5037
5060
return GenericParameterReferenceInfo ();
5038
5061
}
5039
5062
5063
+ // Everything else should be a type parameter.
5064
+ if (!type->isTypeParameter ()) {
5065
+ llvm::errs () << " Unhandled type:\n " ;
5066
+ type->dump (llvm::errs ());
5067
+ abort ();
5068
+ }
5069
+
5040
5070
Type selfTy (genericParam);
5041
5071
if (!type->getRootGenericParam ()->isEqual (selfTy)) {
5042
5072
return GenericParameterReferenceInfo ();
0 commit comments