@@ -2007,33 +2007,39 @@ lowerCaptureContextParameters(TypeConverter &TC, SILDeclRef function,
20072007 continue ;
20082008 }
20092009
2010- auto *varDecl = cast<VarDecl>(capture.getDecl ());
2010+ auto options = SILParameterInfo::Options ();
2011+
2012+ Type type;
2013+ VarDecl *varDecl = nullptr ;
2014+ if (auto *expr = capture.getPackElement ()) {
2015+ type = expr->getType ();
2016+ } else {
2017+ varDecl = cast<VarDecl>(capture.getDecl ());
2018+ type = varDecl->getTypeInContext ();
2019+
2020+ // If we're capturing a parameter pack, wrap it in a tuple.
2021+ if (type->is <PackExpansionType>()) {
2022+ assert (!cast<ParamDecl>(varDecl)->supportsMutation () &&
2023+ " Cannot capture a pack as an lvalue" );
2024+
2025+ SmallVector<TupleTypeElt, 1 > elts;
2026+ elts.push_back (type);
2027+ type = TupleType::get (elts, TC.Context );
2028+ }
2029+
2030+ if (isolatedParam == varDecl) {
2031+ options |= SILParameterInfo::Isolated;
2032+ isolatedParam = nullptr ;
2033+ }
2034+ }
20112035
2012- auto type = varDecl->getTypeInContext ();
20132036 assert (!type->hasLocalArchetype () ||
20142037 (genericSig && origGenericSig &&
20152038 !genericSig->isEqual (origGenericSig)));
20162039 type = mapTypeOutOfContext (type);
20172040
20182041 auto canType = type->getReducedType (
20192042 genericSig ? genericSig : origGenericSig);
2020-
2021- auto options = SILParameterInfo::Options ();
2022- if (isolatedParam == varDecl) {
2023- options |= SILParameterInfo::Isolated;
2024- isolatedParam = nullptr ;
2025- }
2026-
2027- // If we're capturing a parameter pack, wrap it in a tuple.
2028- if (isa<PackExpansionType>(canType)) {
2029- assert (!cast<ParamDecl>(varDecl)->supportsMutation () &&
2030- " Cannot capture a pack as an lvalue" );
2031-
2032- SmallVector<TupleTypeElt, 1 > elts;
2033- elts.push_back (canType);
2034- canType = CanTupleType (TupleType::get (elts, TC.Context ));
2035- }
2036-
20372043 auto &loweredTL =
20382044 TC.getTypeLowering (AbstractionPattern (genericSig, canType), canType,
20392045 expansion);
@@ -2055,6 +2061,8 @@ lowerCaptureContextParameters(TypeConverter &TC, SILDeclRef function,
20552061 break ;
20562062 }
20572063 case CaptureKind::Box: {
2064+ assert (varDecl);
2065+
20582066 // The type in the box is lowered in the minimal context.
20592067 auto minimalLoweredTy =
20602068 TC.getTypeLowering (AbstractionPattern (genericSig, canType), canType,
@@ -2072,6 +2080,8 @@ lowerCaptureContextParameters(TypeConverter &TC, SILDeclRef function,
20722080 break ;
20732081 }
20742082 case CaptureKind::ImmutableBox: {
2083+ assert (varDecl);
2084+
20752085 // The type in the box is lowered in the minimal context.
20762086 auto minimalLoweredTy =
20772087 TC.getTypeLowering (AbstractionPattern (genericSig, canType), canType,
0 commit comments