@@ -3017,12 +3017,12 @@ void swift::fixItEncloseTrailingClosure(ASTContext &ctx,
3017
3017
}
3018
3018
3019
3019
// Perform checkStmtConditionTrailingClosure for single expression.
3020
- static void checkStmtConditionTrailingClosure (TypeChecker &TC , const Expr *E) {
3020
+ static void checkStmtConditionTrailingClosure (ASTContext &ctx , const Expr *E) {
3021
3021
if (E == nullptr || isa<ErrorExpr>(E)) return ;
3022
3022
3023
3023
// Shallow walker. just dig into implicit expression.
3024
3024
class DiagnoseWalker : public ASTWalker {
3025
- TypeChecker &TC ;
3025
+ ASTContext &Ctx ;
3026
3026
3027
3027
void diagnoseIt (const CallExpr *E) {
3028
3028
if (!E->hasTrailingClosure ()) return ;
@@ -3044,13 +3044,13 @@ static void checkStmtConditionTrailingClosure(TypeChecker &TC, const Expr *E) {
3044
3044
closureLabel = TT->getElement (TT->getNumElements () - 1 ).getName ();
3045
3045
}
3046
3046
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);
3050
3050
}
3051
3051
3052
3052
public:
3053
- DiagnoseWalker (TypeChecker &tc ) : TC(tc ) { }
3053
+ DiagnoseWalker (ASTContext &ctx ) : Ctx(ctx ) { }
3054
3054
3055
3055
bool shouldWalkIntoNonSingleExpressionClosure () override { return false ; }
3056
3056
@@ -3065,7 +3065,7 @@ static void checkStmtConditionTrailingClosure(TypeChecker &TC, const Expr *E) {
3065
3065
}
3066
3066
};
3067
3067
3068
- DiagnoseWalker Walker (TC );
3068
+ DiagnoseWalker Walker (ctx );
3069
3069
const_cast <Expr *>(E)->walk (Walker);
3070
3070
}
3071
3071
@@ -3078,23 +3078,23 @@ static void checkStmtConditionTrailingClosure(TypeChecker &TC, const Expr *E) {
3078
3078
// / E.g.:
3079
3079
// / if let _ = arr?.map {$0+1} { ... }
3080
3080
// / for _ in numbers.filter {$0 > 4} { ... }
3081
- static void checkStmtConditionTrailingClosure (TypeChecker &TC , const Stmt *S) {
3081
+ static void checkStmtConditionTrailingClosure (ASTContext &ctx , const Stmt *S) {
3082
3082
if (auto LCS = dyn_cast<LabeledConditionalStmt>(S)) {
3083
3083
for (auto elt : LCS->getCond ()) {
3084
3084
if (elt.getKind () == StmtConditionElement::CK_PatternBinding)
3085
- checkStmtConditionTrailingClosure (TC , elt.getInitializer ());
3085
+ checkStmtConditionTrailingClosure (ctx , elt.getInitializer ());
3086
3086
else if (elt.getKind () == StmtConditionElement::CK_Boolean)
3087
- checkStmtConditionTrailingClosure (TC , elt.getBoolean ());
3087
+ checkStmtConditionTrailingClosure (ctx , elt.getBoolean ());
3088
3088
// No trailing closure for CK_Availability: e.g. `if #available() {}`.
3089
3089
}
3090
3090
} else if (auto SS = dyn_cast<SwitchStmt>(S)) {
3091
- checkStmtConditionTrailingClosure (TC , SS->getSubjectExpr ());
3091
+ checkStmtConditionTrailingClosure (ctx , SS->getSubjectExpr ());
3092
3092
} 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 ());
3095
3095
} else if (auto DCS = dyn_cast<DoCatchStmt>(S)) {
3096
3096
for (auto CS : DCS->getCatches ())
3097
- checkStmtConditionTrailingClosure (TC , CS->getGuardExpr ());
3097
+ checkStmtConditionTrailingClosure (ctx , CS->getGuardExpr ());
3098
3098
}
3099
3099
}
3100
3100
@@ -3486,7 +3486,7 @@ static void diagDeprecatedObjCSelectors(TypeChecker &tc, const DeclContext *dc,
3486
3486
// / if let x: Int = i {
3487
3487
static void
3488
3488
checkImplicitPromotionsInCondition (const StmtConditionElement &cond,
3489
- TypeChecker &TC ) {
3489
+ ASTContext &ctx ) {
3490
3490
auto *p = cond.getPatternOrNull ();
3491
3491
if (!p) return ;
3492
3492
@@ -3499,22 +3499,24 @@ checkImplicitPromotionsInCondition(const StmtConditionElement &cond,
3499
3499
// Check for 'if let' to produce a tuned diagnostic.
3500
3500
if (isa<OptionalSomePattern>(TP->getSubPattern ()) &&
3501
3501
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 ())
3504
3505
.highlight (subExpr->getSourceRange ())
3505
3506
.fixItReplace (TP->getTypeLoc ().getSourceRange (),
3506
3507
ooType->getString ());
3507
3508
return ;
3508
3509
}
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 ())
3512
3513
.highlight (subExpr->getSourceRange ());
3513
3514
return ;
3514
3515
}
3515
3516
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 ())
3518
3520
.highlight (subExpr->getSourceRange ());
3519
3521
}
3520
3522
}
@@ -3996,18 +3998,18 @@ void swift::performSyntacticExprDiagnostics(TypeChecker &TC, const Expr *E,
3996
3998
diagDeprecatedObjCSelectors (TC, DC, E);
3997
3999
}
3998
4000
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));
4001
4003
4002
4004
if (auto switchStmt = dyn_cast<SwitchStmt>(S))
4003
- checkSwitch (TC. Context , switchStmt);
4005
+ checkSwitch (ctx , switchStmt);
4004
4006
4005
- checkStmtConditionTrailingClosure (TC , S);
4007
+ checkStmtConditionTrailingClosure (ctx , S);
4006
4008
4007
4009
// Check for implicit optional promotions in stmt-condition patterns.
4008
4010
if (auto *lcs = dyn_cast<LabeledConditionalStmt>(S))
4009
4011
for (const auto &elt : lcs->getCond ())
4010
- checkImplicitPromotionsInCondition (elt, TC );
4012
+ checkImplicitPromotionsInCondition (elt, ctx );
4011
4013
}
4012
4014
4013
4015
// ===----------------------------------------------------------------------===//
0 commit comments