@@ -203,10 +203,6 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
203
203
while (auto Conv = dyn_cast<ImplicitConversionExpr>(Base))
204
204
Base = Conv->getSubExpr ();
205
205
206
- // Record call arguments.
207
- if (auto Call = dyn_cast<CallExpr>(Base))
208
- CallArgs.insert (Call->getArg ());
209
-
210
206
if (auto *DRE = dyn_cast<DeclRefExpr>(Base)) {
211
207
// Verify metatype uses.
212
208
if (isa<TypeDecl>(DRE->getDecl ())) {
@@ -235,7 +231,14 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
235
231
if (isa<TypeExpr>(Base))
236
232
checkUseOfMetaTypeName (Base);
237
233
234
+ if (auto *TSE = dyn_cast<TupleShuffleExpr>(E)) {
235
+ if (CallArgs.count (TSE))
236
+ CallArgs.insert (TSE->getSubExpr ());
237
+ }
238
+
238
239
if (auto *SE = dyn_cast<SubscriptExpr>(E)) {
240
+ CallArgs.insert (SE->getIndex ());
241
+
239
242
// Implicit InOutExpr's are allowed in the base of a subscript expr.
240
243
if (auto *IOE = dyn_cast<InOutExpr>(SE->getBase ()))
241
244
if (IOE->isImplicit ())
@@ -248,6 +251,13 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
248
251
});
249
252
}
250
253
254
+ if (auto *KPE = dyn_cast<KeyPathExpr>(E)) {
255
+ for (auto Comp : KPE->getComponents ()) {
256
+ if (auto *Arg = Comp.getIndexExpr ())
257
+ CallArgs.insert (Arg);
258
+ }
259
+ }
260
+
251
261
if (auto *AE = dyn_cast<CollectionExpr>(E)) {
252
262
visitCollectionElements (AE, [&](unsigned argIndex, Expr *arg) {
253
263
arg = lookThroughArgument (arg);
@@ -266,6 +276,9 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
266
276
// Check function calls, looking through implicit conversions on the
267
277
// function and inspecting the arguments directly.
268
278
if (auto *Call = dyn_cast<ApplyExpr>(E)) {
279
+ // Record call arguments.
280
+ CallArgs.insert (Call->getArg ());
281
+
269
282
// Warn about surprising implicit optional promotions.
270
283
checkOptionalPromotions (Call);
271
284
@@ -381,6 +394,18 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
381
394
}
382
395
}
383
396
397
+ // Diagnose single-element tuple expressions.
398
+ if (auto *tupleExpr = dyn_cast<TupleExpr>(E)) {
399
+ if (!CallArgs.count (tupleExpr)) {
400
+ if (tupleExpr->getNumElements () == 1 ) {
401
+ TC.diagnose (tupleExpr->getElementNameLoc (0 ),
402
+ diag::tuple_single_element)
403
+ .fixItRemoveChars (tupleExpr->getElementNameLoc (0 ),
404
+ tupleExpr->getElement (0 )->getStartLoc ());
405
+ }
406
+ }
407
+ }
408
+
384
409
return { true , E };
385
410
}
386
411
0 commit comments