@@ -234,8 +234,6 @@ class FailureDiagnosis :public ASTVisitor<FailureDiagnosis, /*exprresult*/bool>{
234
234
Optional<std::function<bool (ArrayRef<OverloadChoice>)>> callback = None,
235
235
bool includeInaccessibleMembers = true);
236
236
237
- bool diagnoseSubscriptErrors (SubscriptExpr *SE, bool performingSet);
238
-
239
237
bool visitExpr (Expr *E);
240
238
bool visitIdentityExpr (IdentityExpr *E);
241
239
bool visitTryExpr (TryExpr *E);
@@ -245,7 +243,6 @@ class FailureDiagnosis :public ASTVisitor<FailureDiagnosis, /*exprresult*/bool>{
245
243
bool visitDictionaryExpr (DictionaryExpr *E);
246
244
bool visitObjectLiteralExpr (ObjectLiteralExpr *E);
247
245
248
- bool visitSubscriptExpr (SubscriptExpr *SE);
249
246
bool visitApplyExpr (ApplyExpr *AE);
250
247
bool visitRebindSelfInConstructorExpr (RebindSelfInConstructorExpr *E);
251
248
};
@@ -1410,163 +1407,6 @@ bool FailureDiagnosis::diagnoseParameterErrors(CalleeCandidateInfo &CCI,
1410
1407
return false ;
1411
1408
}
1412
1409
1413
- bool FailureDiagnosis::diagnoseSubscriptErrors (SubscriptExpr *SE,
1414
- bool inAssignmentDestination) {
1415
- auto baseExpr = typeCheckChildIndependently (SE->getBase ());
1416
- if (!baseExpr) return true ;
1417
- auto baseType = CS.getType (baseExpr);
1418
-
1419
- if (isa<NilLiteralExpr>(baseExpr)) {
1420
- diagnose (baseExpr->getLoc (), diag::cannot_subscript_nil_literal)
1421
- .highlight (baseExpr->getSourceRange ());
1422
- return true ;
1423
- }
1424
-
1425
- std::function<bool (ArrayRef<OverloadChoice>)> callback =
1426
- [&](ArrayRef<OverloadChoice> candidates) -> bool {
1427
- CalleeCandidateInfo calleeInfo (Type (), candidates, SE->hasTrailingClosure (),
1428
- CS, /* selfAlreadyApplied*/ false );
1429
-
1430
- // We're about to typecheck the index list, which needs to be processed with
1431
- // self already applied.
1432
- for (unsigned i = 0 , e = calleeInfo.size (); i != e; ++i)
1433
- calleeInfo.candidates [i].skipCurriedSelf = true ;
1434
-
1435
- auto indexExpr =
1436
- typeCheckArgumentChildIndependently (SE->getIndex (), Type (), calleeInfo);
1437
- if (!indexExpr)
1438
- return true ;
1439
-
1440
- // Back to analyzing the candidate list with self applied.
1441
- for (unsigned i = 0 , e = calleeInfo.size (); i != e; ++i)
1442
- calleeInfo.candidates [i].skipCurriedSelf = false ;
1443
-
1444
- ArrayRef<Identifier> argLabels = SE->getArgumentLabels ();
1445
- if (diagnoseParameterErrors (calleeInfo, SE, indexExpr, argLabels))
1446
- return true ;
1447
-
1448
- auto indexType = CS.getType (indexExpr);
1449
-
1450
- auto decomposedBaseType = decomposeArgType (baseType, {Identifier ()});
1451
- auto decomposedIndexType = decomposeArgType (indexType, argLabels);
1452
- calleeInfo.filterList (
1453
- [&](OverloadCandidate cand) -> CalleeCandidateInfo::ClosenessResultTy {
1454
- // Classify how close this match is. Non-subscript decls don't match.
1455
- auto subscriptDecl = dyn_cast_or_null<SubscriptDecl>(cand.getDecl ());
1456
- if (!subscriptDecl ||
1457
- (inAssignmentDestination && !subscriptDecl->supportsMutation ()))
1458
- return {CC_GeneralMismatch, {}};
1459
-
1460
- // Check whether the self type matches.
1461
- auto selfConstraint = CC_ExactMatch;
1462
- if (calleeInfo.evaluateCloseness (cand, decomposedBaseType).first !=
1463
- CC_ExactMatch)
1464
- selfConstraint = CC_SelfMismatch;
1465
-
1466
- // Set a flag to look past the self argument to the indices.
1467
- cand.skipCurriedSelf = true ;
1468
-
1469
- // Explode out multi-index subscripts to find the best match.
1470
- auto indexResult =
1471
- calleeInfo.evaluateCloseness (cand, decomposedIndexType);
1472
- if (selfConstraint > indexResult.first )
1473
- return {selfConstraint, {}};
1474
- return indexResult;
1475
- });
1476
-
1477
- // If the closest matches all mismatch on self, we either have something
1478
- // that cannot be subscripted, or an ambiguity.
1479
- if (calleeInfo.closeness == CC_SelfMismatch) {
1480
- diagnose (SE->getLoc (), diag::cannot_subscript_base, baseType)
1481
- .highlight (SE->getBase ()->getSourceRange ());
1482
- // FIXME: Should suggest overload set, but we're not ready for that until
1483
- // it points to candidates and identifies the self type in the diagnostic.
1484
- // calleeInfo.suggestPotentialOverloads(SE->getLoc());
1485
- return true ;
1486
- }
1487
-
1488
- // Any other failures relate to the index list.
1489
- for (unsigned i = 0 , e = calleeInfo.size (); i != e; ++i)
1490
- calleeInfo.candidates [i].skipCurriedSelf = true ;
1491
-
1492
- // TODO: Is there any reason to check for CC_NonLValueInOut here?
1493
-
1494
- if (calleeInfo.closeness == CC_ExactMatch) {
1495
- auto message = diag::ambiguous_subscript;
1496
-
1497
- // If there is an exact match on the argument with
1498
- // a single candidate, let's type-check subscript
1499
- // as a whole to figure out if there is any structural
1500
- // problem after all.
1501
- if (calleeInfo.size () == 1 ) {
1502
- Expr *expr = SE;
1503
- ConcreteDeclRef decl = nullptr ;
1504
- message = diag::cannot_subscript_with_index;
1505
-
1506
- if (TypeChecker::getTypeOfExpressionWithoutApplying (expr, CS.DC , decl))
1507
- return false ;
1508
-
1509
- // If we are down to a single candidate but with an unresolved
1510
- // index type, we can substitute in the base type to get a simpler
1511
- // and more concrete expected type for this subscript decl, in order
1512
- // to diagnose a better error.
1513
- if (baseType && indexType->hasUnresolvedType ()) {
1514
- auto cand = calleeInfo.candidates [0 ];
1515
- auto candType = baseType->getTypeOfMember (CS.DC ->getParentModule (),
1516
- cand.getDecl (), nullptr );
1517
- if (auto *candFunc = candType->getAs <FunctionType>()) {
1518
- auto paramsType = FunctionType::composeInput (CS.getASTContext (),
1519
- candFunc->getParams (),
1520
- false );
1521
- if (!typeCheckChildIndependently (
1522
- indexExpr, paramsType, CTP_CallArgument, TCC_ForceRecheck))
1523
- return true ;
1524
- }
1525
- }
1526
- }
1527
-
1528
- diagnose (SE->getLoc (), message, baseType, indexType)
1529
- .highlight (indexExpr->getSourceRange ())
1530
- .highlight (baseExpr->getSourceRange ());
1531
-
1532
- // FIXME: suggestPotentialOverloads should do this.
1533
- // calleeInfo.suggestPotentialOverloads(SE->getLoc());
1534
- for (auto candidate : calleeInfo.candidates )
1535
- if (auto decl = candidate.getDecl ())
1536
- diagnose (decl, diag::found_candidate);
1537
- else
1538
- diagnose (candidate.getExpr ()->getLoc (), diag::found_candidate);
1539
-
1540
- return true ;
1541
- }
1542
-
1543
- if (diagnoseParameterErrors (calleeInfo, SE, indexExpr, argLabels))
1544
- return true ;
1545
-
1546
- // Diagnose some simple and common errors.
1547
- if (calleeInfo.diagnoseSimpleErrors (SE))
1548
- return true ;
1549
-
1550
- diagnose (SE->getLoc (), diag::cannot_subscript_with_index, baseType,
1551
- indexType);
1552
-
1553
- calleeInfo.suggestPotentialOverloads (SE->getLoc ());
1554
- return true ;
1555
- };
1556
-
1557
- auto locator =
1558
- CS.getConstraintLocator (SE, ConstraintLocator::SubscriptMember);
1559
-
1560
- return diagnoseMemberFailures (SE, baseExpr, ConstraintKind::ValueMember,
1561
- DeclNameRef::createSubscript (),
1562
- FunctionRefKind::DoubleApply, locator,
1563
- callback);
1564
- }
1565
-
1566
- bool FailureDiagnosis::visitSubscriptExpr (SubscriptExpr *SE) {
1567
- return diagnoseSubscriptErrors (SE, /* inAssignmentDestination = */ false );
1568
- }
1569
-
1570
1410
// Check if there is a structural problem in the function expression
1571
1411
// by performing type checking with the option to allow unresolved
1572
1412
// type variables. If that is going to produce a function type with
0 commit comments