Skip to content

Commit 42c7333

Browse files
committed
[CSGen] Diagnose subscripting a nil literal in CSGen.
1 parent 9a2b29b commit 42c7333

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,12 +1418,6 @@ bool FailureDiagnosis::diagnoseSubscriptErrors(SubscriptExpr *SE,
14181418
if (!baseExpr) return true;
14191419
auto baseType = CS.getType(baseExpr);
14201420

1421-
if (isa<NilLiteralExpr>(baseExpr)) {
1422-
diagnose(baseExpr->getLoc(), diag::cannot_subscript_nil_literal)
1423-
.highlight(baseExpr->getSourceRange());
1424-
return true;
1425-
}
1426-
14271421
std::function<bool(ArrayRef<OverloadChoice>)> callback =
14281422
[&](ArrayRef<OverloadChoice> candidates) -> bool {
14291423
CalleeCandidateInfo calleeInfo(Type(), candidates, SE->hasTrailingClosure(),

lib/Sema/CSGen.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,13 +1785,20 @@ namespace {
17851785
}
17861786

17871787
Type visitSubscriptExpr(SubscriptExpr *expr) {
1788+
auto &ctx = CS.getASTContext();
17881789
ValueDecl *decl = nullptr;
17891790
if (expr->hasDecl()) {
17901791
decl = expr->getDecl().getDecl();
17911792
if (decl->isInvalid())
17921793
return Type();
17931794
}
17941795

1796+
if (auto nilLiteral = dyn_cast<NilLiteralExpr>(expr->getBase())) {
1797+
ctx.Diags.diagnose(nilLiteral->getLoc(),
1798+
diag::cannot_subscript_nil_literal);
1799+
return nullptr;
1800+
}
1801+
17951802
return addSubscriptConstraints(expr, CS.getType(expr->getBase()),
17961803
expr->getIndex(),
17971804
decl, expr->getArgumentLabels(),

0 commit comments

Comments
 (0)