Skip to content

Commit bd6fd38

Browse files
committed
performStmtDiagnostics doesn't need a TypeChecker
1 parent d8dfbbc commit bd6fd38

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3017,12 +3017,12 @@ void swift::fixItEncloseTrailingClosure(ASTContext &ctx,
30173017
}
30183018

30193019
// Perform checkStmtConditionTrailingClosure for single expression.
3020-
static void checkStmtConditionTrailingClosure(TypeChecker &TC, const Expr *E) {
3020+
static void checkStmtConditionTrailingClosure(ASTContext &ctx, const Expr *E) {
30213021
if (E == nullptr || isa<ErrorExpr>(E)) return;
30223022

30233023
// Shallow walker. just dig into implicit expression.
30243024
class DiagnoseWalker : public ASTWalker {
3025-
TypeChecker &TC;
3025+
ASTContext &Ctx;
30263026

30273027
void diagnoseIt(const CallExpr *E) {
30283028
if (!E->hasTrailingClosure()) return;
@@ -3044,13 +3044,13 @@ static void checkStmtConditionTrailingClosure(TypeChecker &TC, const Expr *E) {
30443044
closureLabel = TT->getElement(TT->getNumElements() - 1).getName();
30453045
}
30463046

3047-
auto diag = TC.diagnose(closureLoc,
3048-
diag::trailing_closure_requires_parens);
3049-
fixItEncloseTrailingClosure(TC, diag, E, closureLabel);
3047+
auto diag = Ctx.Diags.diagnose(closureLoc,
3048+
diag::trailing_closure_requires_parens);
3049+
fixItEncloseTrailingClosure(Ctx, diag, E, closureLabel);
30503050
}
30513051

30523052
public:
3053-
DiagnoseWalker(TypeChecker &tc) : TC(tc) { }
3053+
DiagnoseWalker(ASTContext &ctx) : Ctx(ctx) { }
30543054

30553055
bool shouldWalkIntoNonSingleExpressionClosure() override { return false; }
30563056

@@ -3065,7 +3065,7 @@ static void checkStmtConditionTrailingClosure(TypeChecker &TC, const Expr *E) {
30653065
}
30663066
};
30673067

3068-
DiagnoseWalker Walker(TC);
3068+
DiagnoseWalker Walker(ctx);
30693069
const_cast<Expr *>(E)->walk(Walker);
30703070
}
30713071

@@ -3078,23 +3078,23 @@ static void checkStmtConditionTrailingClosure(TypeChecker &TC, const Expr *E) {
30783078
/// E.g.:
30793079
/// if let _ = arr?.map {$0+1} { ... }
30803080
/// for _ in numbers.filter {$0 > 4} { ... }
3081-
static void checkStmtConditionTrailingClosure(TypeChecker &TC, const Stmt *S) {
3081+
static void checkStmtConditionTrailingClosure(ASTContext &ctx, const Stmt *S) {
30823082
if (auto LCS = dyn_cast<LabeledConditionalStmt>(S)) {
30833083
for (auto elt : LCS->getCond()) {
30843084
if (elt.getKind() == StmtConditionElement::CK_PatternBinding)
3085-
checkStmtConditionTrailingClosure(TC, elt.getInitializer());
3085+
checkStmtConditionTrailingClosure(ctx, elt.getInitializer());
30863086
else if (elt.getKind() == StmtConditionElement::CK_Boolean)
3087-
checkStmtConditionTrailingClosure(TC, elt.getBoolean());
3087+
checkStmtConditionTrailingClosure(ctx, elt.getBoolean());
30883088
// No trailing closure for CK_Availability: e.g. `if #available() {}`.
30893089
}
30903090
} else if (auto SS = dyn_cast<SwitchStmt>(S)) {
3091-
checkStmtConditionTrailingClosure(TC, SS->getSubjectExpr());
3091+
checkStmtConditionTrailingClosure(ctx, SS->getSubjectExpr());
30923092
} else if (auto FES = dyn_cast<ForEachStmt>(S)) {
3093-
checkStmtConditionTrailingClosure(TC, FES->getSequence());
3094-
checkStmtConditionTrailingClosure(TC, FES->getWhere());
3093+
checkStmtConditionTrailingClosure(ctx, FES->getSequence());
3094+
checkStmtConditionTrailingClosure(ctx, FES->getWhere());
30953095
} else if (auto DCS = dyn_cast<DoCatchStmt>(S)) {
30963096
for (auto CS : DCS->getCatches())
3097-
checkStmtConditionTrailingClosure(TC, CS->getGuardExpr());
3097+
checkStmtConditionTrailingClosure(ctx, CS->getGuardExpr());
30983098
}
30993099
}
31003100

@@ -3486,7 +3486,7 @@ static void diagDeprecatedObjCSelectors(TypeChecker &tc, const DeclContext *dc,
34863486
/// if let x: Int = i {
34873487
static void
34883488
checkImplicitPromotionsInCondition(const StmtConditionElement &cond,
3489-
TypeChecker &TC) {
3489+
ASTContext &ctx) {
34903490
auto *p = cond.getPatternOrNull();
34913491
if (!p) return;
34923492

@@ -3499,22 +3499,24 @@ checkImplicitPromotionsInCondition(const StmtConditionElement &cond,
34993499
// Check for 'if let' to produce a tuned diagnostic.
35003500
if (isa<OptionalSomePattern>(TP->getSubPattern()) &&
35013501
TP->getSubPattern()->isImplicit()) {
3502-
TC.diagnose(cond.getIntroducerLoc(), diag::optional_check_promotion,
3503-
subExpr->getType())
3502+
ctx.Diags.diagnose(cond.getIntroducerLoc(),
3503+
diag::optional_check_promotion,
3504+
subExpr->getType())
35043505
.highlight(subExpr->getSourceRange())
35053506
.fixItReplace(TP->getTypeLoc().getSourceRange(),
35063507
ooType->getString());
35073508
return;
35083509
}
3509-
TC.diagnose(cond.getIntroducerLoc(),
3510-
diag::optional_pattern_match_promotion,
3511-
subExpr->getType(), cond.getInitializer()->getType())
3510+
ctx.Diags.diagnose(cond.getIntroducerLoc(),
3511+
diag::optional_pattern_match_promotion,
3512+
subExpr->getType(), cond.getInitializer()->getType())
35123513
.highlight(subExpr->getSourceRange());
35133514
return;
35143515
}
35153516

3516-
TC.diagnose(cond.getIntroducerLoc(), diag::optional_check_nonoptional,
3517-
subExpr->getType())
3517+
ctx.Diags.diagnose(cond.getIntroducerLoc(),
3518+
diag::optional_check_nonoptional,
3519+
subExpr->getType())
35183520
.highlight(subExpr->getSourceRange());
35193521
}
35203522
}
@@ -3996,18 +3998,18 @@ void swift::performSyntacticExprDiagnostics(TypeChecker &TC, const Expr *E,
39963998
diagDeprecatedObjCSelectors(TC, DC, E);
39973999
}
39984000

3999-
void swift::performStmtDiagnostics(TypeChecker &TC, const Stmt *S) {
4000-
TypeChecker::checkUnsupportedProtocolType(TC.Context, const_cast<Stmt *>(S));
4001+
void swift::performStmtDiagnostics(ASTContext &ctx, const Stmt *S) {
4002+
TypeChecker::checkUnsupportedProtocolType(ctx, const_cast<Stmt *>(S));
40014003

40024004
if (auto switchStmt = dyn_cast<SwitchStmt>(S))
4003-
checkSwitch(TC.Context, switchStmt);
4005+
checkSwitch(ctx, switchStmt);
40044006

4005-
checkStmtConditionTrailingClosure(TC, S);
4007+
checkStmtConditionTrailingClosure(ctx, S);
40064008

40074009
// Check for implicit optional promotions in stmt-condition patterns.
40084010
if (auto *lcs = dyn_cast<LabeledConditionalStmt>(S))
40094011
for (const auto &elt : lcs->getCond())
4010-
checkImplicitPromotionsInCondition(elt, TC);
4012+
checkImplicitPromotionsInCondition(elt, ctx);
40114013
}
40124014

40134015
//===----------------------------------------------------------------------===//

lib/Sema/MiscDiagnostics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void performSyntacticExprDiagnostics(TypeChecker &TC, const Expr *E,
4040
bool isExprStmt);
4141

4242
/// Emit diagnostics for a given statement.
43-
void performStmtDiagnostics(TypeChecker &TC, const Stmt *S);
43+
void performStmtDiagnostics(ASTContext &ctx, const Stmt *S);
4444

4545
void performAbstractFuncDeclDiagnostics(AbstractFunctionDecl *AFD,
4646
BraceStmt *body);

lib/Sema/TypeCheckStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
410410
if (S2 == nullptr)
411411
return true;
412412
S = S2;
413-
performStmtDiagnostics(TC, S);
413+
performStmtDiagnostics(getASTContext(), S);
414414
return false;
415415
}
416416

0 commit comments

Comments
 (0)