Skip to content

Commit e26794a

Browse files
committed
[CSDiag] Remove diagnoseSubscriptErrors from CSDiag
1 parent 834eee6 commit e26794a

File tree

1 file changed

+0
-154
lines changed

1 file changed

+0
-154
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 0 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,6 @@ class FailureDiagnosis :public ASTVisitor<FailureDiagnosis, /*exprresult*/bool>{
234234
Optional<std::function<bool(ArrayRef<OverloadChoice>)>> callback = None,
235235
bool includeInaccessibleMembers = true);
236236

237-
bool diagnoseSubscriptErrors(SubscriptExpr *SE, bool performingSet);
238-
239237
bool visitExpr(Expr *E);
240238
bool visitIdentityExpr(IdentityExpr *E);
241239
bool visitTryExpr(TryExpr *E);
@@ -245,7 +243,6 @@ class FailureDiagnosis :public ASTVisitor<FailureDiagnosis, /*exprresult*/bool>{
245243
bool visitDictionaryExpr(DictionaryExpr *E);
246244
bool visitObjectLiteralExpr(ObjectLiteralExpr *E);
247245

248-
bool visitSubscriptExpr(SubscriptExpr *SE);
249246
bool visitApplyExpr(ApplyExpr *AE);
250247
bool visitCoerceExpr(CoerceExpr *CE);
251248
bool visitIfExpr(IfExpr *IE);
@@ -1412,157 +1409,6 @@ bool FailureDiagnosis::diagnoseParameterErrors(CalleeCandidateInfo &CCI,
14121409
return false;
14131410
}
14141411

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

0 commit comments

Comments
 (0)