@@ -296,9 +296,30 @@ bool SILType::canRefCast(SILType operTy, SILType resultTy, SILModule &M) {
296
296
&& toTy.isHeapObjectReferenceType ();
297
297
}
298
298
299
+ static bool needsFieldSubstitutions (const AbstractionPattern &origType) {
300
+ if (origType.isTypeParameter ()) return false ;
301
+ auto type = origType.getType ();
302
+ if (!type->hasTypeParameter ()) return false ;
303
+ return type.findIf ([](CanType type) {
304
+ return isa<PackExpansionType>(type);
305
+ });
306
+ }
307
+
308
+ static void addFieldSubstitutionsIfNeeded (TypeConverter &TC, SILType ty,
309
+ ValueDecl *field,
310
+ AbstractionPattern &origType) {
311
+ if (needsFieldSubstitutions (origType)) {
312
+ auto subMap = ty.getASTType ()->getContextSubstitutionMap (
313
+ &TC.M , field->getDeclContext ());
314
+ origType = origType.withSubstitutions (subMap);
315
+ }
316
+ }
317
+
299
318
SILType SILType::getFieldType (VarDecl *field, TypeConverter &TC,
300
319
TypeExpansionContext context) const {
301
320
AbstractionPattern origFieldTy = TC.getAbstractionPattern (field);
321
+ addFieldSubstitutionsIfNeeded (TC, *this , field, origFieldTy);
322
+
302
323
CanType substFieldTy;
303
324
if (field->hasClangNode ()) {
304
325
substFieldTy = origFieldTy.getType ();
@@ -348,6 +369,9 @@ SILType SILType::getEnumElementType(EnumElementDecl *elt, TypeConverter &TC,
348
369
getCategory ());
349
370
}
350
371
372
+ auto origEltType = TC.getAbstractionPattern (elt);
373
+ addFieldSubstitutionsIfNeeded (TC, *this , elt, origEltType);
374
+
351
375
auto substEltTy = getASTType ()->getTypeOfMember (
352
376
&TC.M , elt, elt->getArgumentInterfaceType ());
353
377
auto loweredTy = TC.getLoweredRValueType (
0 commit comments