@@ -1067,6 +1067,42 @@ bool SILParser::parseASTType(CanType &result,
10671067 return false ;
10681068}
10691069
1070+ bool SILParser::parseASTTypeOrValue (CanType &result,
1071+ GenericSignature genericSig,
1072+ GenericParamList *genericParams,
1073+ bool forceContextualType) {
1074+ auto parsedType = P.parseTypeOrValue ();
1075+ if (parsedType.isNull ()) return true ;
1076+
1077+ // If we weren't given a specific generic context to resolve the type
1078+ // within, use the contextual generic parameters and always produce
1079+ // a contextual type. Otherwise, produce a contextual type only if
1080+ // we were asked for one.
1081+ bool wantContextualType = forceContextualType;
1082+ if (!genericSig) {
1083+ genericSig = ContextGenericSig;
1084+ wantContextualType = true ;
1085+ }
1086+ if (genericParams == nullptr )
1087+ genericParams = ContextGenericParams;
1088+
1089+ bindSILGenericParams (parsedType.get ());
1090+
1091+ auto resolvedType = performTypeResolution (
1092+ parsedType.get (), /* isSILType=*/ false , genericSig, genericParams);
1093+ if (wantContextualType && genericSig) {
1094+ resolvedType = genericSig.getGenericEnvironment ()
1095+ ->mapTypeIntoContext (resolvedType);
1096+ }
1097+
1098+ if (resolvedType->hasError ())
1099+ return true ;
1100+
1101+ result = resolvedType->getCanonicalType ();
1102+
1103+ return false ;
1104+ }
1105+
10701106void SILParser::bindSILGenericParams (TypeRepr *TyR) {
10711107 // Resolve the generic environments for parsed generic function and box types.
10721108 class HandleSILGenericParamsWalker : public ASTWalker {
@@ -3122,7 +3158,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
31223158 CanType paramType;
31233159 if (parseSILType (Ty) ||
31243160 parseVerbatim (" for" ) ||
3125- parseASTType (paramType))
3161+ parseASTTypeOrValue (paramType))
31263162 return true ;
31273163
31283164 ResultVal = B.createTypeValue (InstLoc, Ty, paramType);
0 commit comments