@@ -946,29 +946,30 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
946
946
PreviousFallthrough = S;
947
947
return S;
948
948
}
949
-
950
- Stmt *visitSwitchStmt (SwitchStmt *S ) {
949
+
950
+ Stmt *visitSwitchStmt (SwitchStmt *switchStmt ) {
951
951
// Type-check the subject expression.
952
- Expr *subjectExpr = S ->getSubjectExpr ();
952
+ Expr *subjectExpr = switchStmt ->getSubjectExpr ();
953
953
auto resultTy = TC.typeCheckExpression (subjectExpr, DC);
954
954
auto limitExhaustivityChecks = !resultTy;
955
955
if (Expr *newSubjectExpr = TC.coerceToRValue (subjectExpr))
956
956
subjectExpr = newSubjectExpr;
957
- S ->setSubjectExpr (subjectExpr);
958
- Type subjectType = S ->getSubjectExpr ()->getType ();
957
+ switchStmt ->setSubjectExpr (subjectExpr);
958
+ Type subjectType = switchStmt ->getSubjectExpr ()->getType ();
959
959
960
960
// Type-check the case blocks.
961
961
AddSwitchNest switchNest (*this );
962
- AddLabeledStmt labelNest (*this , S );
962
+ AddLabeledStmt labelNest (*this , switchStmt );
963
963
964
964
// Pre-emptively visit all Decls (#if/#warning/#error) that still exist in
965
965
// the list of raw cases.
966
- for (auto node : S->getRawCases ()) {
967
- if (!node.is <Decl*>()) continue ;
968
- TC.typeCheckDecl (node.get <Decl*>());
966
+ for (auto &node : switchStmt->getRawCases ()) {
967
+ if (!node.is <Decl *>())
968
+ continue ;
969
+ TC.typeCheckDecl (node.get <Decl *>());
969
970
}
970
971
971
- auto cases = S ->getCases ();
972
+ auto cases = switchStmt ->getCases ();
972
973
CaseStmt *previousBlock = nullptr ;
973
974
for (auto i = cases.begin (), e = cases.end (); i != e; ++i) {
974
975
auto *caseBlock = *i;
@@ -1000,36 +1001,39 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
1000
1001
1001
1002
// For each variable in the pattern, make sure its type is identical to what it
1002
1003
// was in the first label item's pattern.
1003
- auto firstPattern = caseBlock->getCaseLabelItems ()[0 ].getPattern ();
1004
+ auto * firstPattern = caseBlock->getCaseLabelItems ()[0 ].getPattern ();
1004
1005
SmallVector<VarDecl *, 4 > vars;
1005
1006
firstPattern->collectVariables (vars);
1006
- pattern->forEachVariable ([&](VarDecl *VD ) {
1007
- if (!VD ->hasName ())
1007
+ pattern->forEachVariable ([&](VarDecl *vd ) {
1008
+ if (!vd ->hasName ())
1008
1009
return ;
1009
1010
for (auto *expected : vars) {
1010
- if (expected->hasName () && expected->getName () == VD->getName ()) {
1011
- if (VD->hasType () && expected->hasType () && !expected->isInvalid () &&
1012
- !VD->getType ()->isEqual (expected->getType ())) {
1013
- TC.diagnose (VD->getLoc (), diag::type_mismatch_multiple_pattern_list,
1014
- VD->getType (), expected->getType ());
1015
- VD->markInvalid ();
1011
+ if (expected->hasName () && expected->getName () == vd->getName ()) {
1012
+ if (vd->hasType () && expected->hasType () &&
1013
+ !expected->isInvalid () &&
1014
+ !vd->getType ()->isEqual (expected->getType ())) {
1015
+ TC.diagnose (vd->getLoc (),
1016
+ diag::type_mismatch_multiple_pattern_list,
1017
+ vd->getType (), expected->getType ());
1018
+ vd->markInvalid ();
1016
1019
expected->markInvalid ();
1017
1020
}
1018
- if (expected->isLet () != VD->isLet ()) {
1019
- auto diag = TC.diagnose (VD->getLoc (),
1020
- diag::mutability_mismatch_multiple_pattern_list,
1021
- VD->isLet (), expected->isLet ());
1021
+ if (expected->isLet () != vd->isLet ()) {
1022
+ auto diag = TC.diagnose (
1023
+ vd->getLoc (),
1024
+ diag::mutability_mismatch_multiple_pattern_list,
1025
+ vd->isLet (), expected->isLet ());
1022
1026
1023
1027
VarPattern *foundVP = nullptr ;
1024
- VD ->getParentPattern ()->forEachNode ([&](Pattern *P) {
1028
+ vd ->getParentPattern ()->forEachNode ([&](Pattern *P) {
1025
1029
if (auto *VP = dyn_cast<VarPattern>(P))
1026
- if (VP->getSingleVar () == VD )
1030
+ if (VP->getSingleVar () == vd )
1027
1031
foundVP = VP;
1028
1032
});
1029
1033
if (foundVP)
1030
1034
diag.fixItReplace (foundVP->getLoc (),
1031
1035
expected->isLet () ? " let" : " var" );
1032
- VD ->markInvalid ();
1036
+ vd ->markInvalid ();
1033
1037
expected->markInvalid ();
1034
1038
}
1035
1039
return ;
@@ -1061,7 +1065,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
1061
1065
limitExhaustivityChecks = true ;
1062
1066
}
1063
1067
1064
- const CaseLabelItem &labelItem = caseBlock->getCaseLabelItems ().front ();
1068
+ const auto &labelItem = caseBlock->getCaseLabelItems ().front ();
1065
1069
if (labelItem.getGuardExpr () && !labelItem.isDefault ()) {
1066
1070
TC.diagnose (labelItem.getStartLoc (),
1067
1071
diag::unknown_case_where_clause)
@@ -1081,14 +1085,14 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
1081
1085
// includes our first label item's pattern bindings and types.
1082
1086
if (PreviousFallthrough && previousBlock) {
1083
1087
auto firstPattern = caseBlock->getCaseLabelItems ()[0 ].getPattern ();
1084
- SmallVector<VarDecl *, 4 > Vars ;
1085
- firstPattern->collectVariables (Vars );
1088
+ SmallVector<VarDecl *, 4 > vars ;
1089
+ firstPattern->collectVariables (vars );
1086
1090
1087
1091
for (auto &labelItem : previousBlock->getCaseLabelItems ()) {
1088
1092
const Pattern *pattern = labelItem.getPattern ();
1089
1093
SmallVector<VarDecl *, 4 > PreviousVars;
1090
1094
pattern->collectVariables (PreviousVars);
1091
- for (auto expected : Vars ) {
1095
+ for (auto expected : vars ) {
1092
1096
bool matched = false ;
1093
1097
if (!expected->hasName ())
1094
1098
continue ;
@@ -1120,11 +1124,11 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
1120
1124
previousBlock = caseBlock;
1121
1125
}
1122
1126
1123
- if (!S ->isImplicit ()) {
1124
- TC.checkSwitchExhaustiveness (S , DC, limitExhaustivityChecks);
1127
+ if (!switchStmt ->isImplicit ()) {
1128
+ TC.checkSwitchExhaustiveness (switchStmt , DC, limitExhaustivityChecks);
1125
1129
}
1126
1130
1127
- return S ;
1131
+ return switchStmt ;
1128
1132
}
1129
1133
1130
1134
Stmt *visitCaseStmt (CaseStmt *S) {
0 commit comments