@@ -4904,7 +4904,7 @@ findGenericParameterReferencesRec(CanGenericSignature genericSig,
49044904 TypePosition position,
49054905 bool canBeCovariantResult) {
49064906 // If there are no type parameters, we're done.
4907- if (!type->hasTypeParameter ())
4907+ if (!type->getCanonicalType ()-> hasTypeParameter ())
49084908 return GenericParameterReferenceInfo ();
49094909
49104910 // Tuples preserve variance.
@@ -4954,7 +4954,7 @@ findGenericParameterReferencesRec(CanGenericSignature genericSig,
49544954 // Don't forget to look in the parent.
49554955 if (const auto parent = nominal->getParent ()) {
49564956 info |= findGenericParameterReferencesRec (
4957- genericSig, genericParam, parent, position ,
4957+ genericSig, genericParam, parent, TypePosition::Invariant ,
49584958 /* canBeCovariantResult=*/ false );
49594959 }
49604960
@@ -5033,10 +5033,40 @@ findGenericParameterReferencesRec(CanGenericSignature genericSig,
50335033 return info;
50345034 }
50355035
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>()) {
50375060 return GenericParameterReferenceInfo ();
50385061 }
50395062
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+
50405070 Type selfTy (genericParam);
50415071 if (!type->getRootGenericParam ()->isEqual (selfTy)) {
50425072 return GenericParameterReferenceInfo ();
0 commit comments