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