@@ -233,6 +233,12 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
233
233
if (auto *IOE = dyn_cast<InOutExpr>(SE->getBase ()))
234
234
if (IOE->isImplicit ())
235
235
AcceptableInOutExprs.insert (IOE);
236
+
237
+ visitIndices (SE, [&](unsigned argIndex, Expr *arg) {
238
+ arg = lookThroughArgument (arg);
239
+ if (auto *DRE = dyn_cast<DeclRefExpr>(arg))
240
+ checkNoEscapeParameterUse (DRE, SE, OperandKind::Argument);
241
+ });
236
242
}
237
243
238
244
// Check decl refs in withoutActuallyEscaping blocks.
@@ -352,10 +358,12 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
352
358
return { true , E };
353
359
}
354
360
355
- static void visitArguments (ApplyExpr *apply,
356
- llvm::function_ref<void (unsigned , Expr*)> fn) {
357
- auto *arg = apply->getArg ();
358
-
361
+ // / Visit the argument/s represented by either a ParenExpr or TupleExpr,
362
+ // / unshuffling if needed. If any other kind of expression, will pass it
363
+ // / straight back.
364
+ static void argExprVisitArguments (Expr* arg,
365
+ llvm::function_ref
366
+ <void (unsigned , Expr*)> fn) {
359
367
// The argument could be shuffled if it includes default arguments,
360
368
// label differences, or other exciting things like that.
361
369
if (auto *TSE = dyn_cast<TupleShuffleExpr>(arg))
@@ -373,6 +381,18 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
373
381
}
374
382
}
375
383
384
+ static void visitIndices (SubscriptExpr *subscript,
385
+ llvm::function_ref<void (unsigned , Expr*)> fn) {
386
+ auto *indexArgs = subscript->getIndex ();
387
+ argExprVisitArguments (indexArgs, fn);
388
+ }
389
+
390
+ static void visitArguments (ApplyExpr *apply,
391
+ llvm::function_ref<void (unsigned , Expr*)> fn) {
392
+ auto *arg = apply->getArg ();
393
+ argExprVisitArguments (arg, fn);
394
+ }
395
+
376
396
static Expr *lookThroughArgument (Expr *arg) {
377
397
while (1 ) {
378
398
if (auto conv = dyn_cast<ImplicitConversionExpr>(arg))
@@ -655,6 +675,9 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
655
675
if (isa<ParamDecl>(DRE->getDecl ()) && useKind == OperandKind::Callee)
656
676
checkNoEscapeParameterCall (apply);
657
677
return ;
678
+ } else if (isa<SubscriptExpr>(parent)
679
+ && useKind == OperandKind::Argument) {
680
+ return ;
658
681
} else if (isa<MakeTemporarilyEscapableExpr>(parent)) {
659
682
return ;
660
683
}
0 commit comments