@@ -75,15 +75,15 @@ bool hasExistentialAnyInType(Type type) {
75
75
return type->getCanonicalType ().findIf (isExistentialType);
76
76
}
77
77
78
- void checkExistentialInFunctionReturnType (FuncDecl *FD,
78
+ void checkExistentialInFunctionReturnType (const FuncDecl *FD,
79
79
DiagnosticEngine &Diags) {
80
80
Type T = FD->getResultInterfaceType ();
81
81
82
82
if (hasExistentialAnyInType (T))
83
83
Diags.diagnose (FD, diag::perf_hint_func_returns_existential, FD);
84
84
}
85
85
86
- void checkExistentialInClosureReturnType (ClosureExpr *CE,
86
+ void checkExistentialInClosureReturnType (const ClosureExpr *CE,
87
87
DiagnosticEngine &Diags) {
88
88
Type T = CE->getResultType ();
89
89
@@ -132,6 +132,13 @@ class PerformanceHintDiagnosticWalker final : public ASTWalker {
132
132
if (P->isImplicit ())
133
133
return Action::SkipNode (P);
134
134
135
+ return Action::Continue (P);
136
+ }
137
+
138
+ PostWalkResult<Pattern *> walkToPatternPost (Pattern *P) override {
139
+ assert (!P->isImplicit () &&
140
+ " Traversing implicit patterns is disabled in the pre-walk visitor" );
141
+
135
142
if (const AnyPattern *AP = dyn_cast<AnyPattern>(P)) {
136
143
checkExistentialInPatternType (AP, Ctx.Diags );
137
144
}
@@ -143,10 +150,6 @@ class PerformanceHintDiagnosticWalker final : public ASTWalker {
143
150
if (E->isImplicit ())
144
151
return Action::SkipNode (E);
145
152
146
- if (const ClosureExpr* Closure = dyn_cast<ClosureExpr>(E)) {
147
- checkImplicitCopyReturnType (Closure, Ctx.Diags );
148
- }
149
-
150
153
return Action::Continue (E);
151
154
}
152
155
@@ -155,8 +158,9 @@ class PerformanceHintDiagnosticWalker final : public ASTWalker {
155
158
!E->isImplicit () &&
156
159
" Traversing implicit expressions is disabled in the pre-walk visitor" );
157
160
158
- if (auto Closure = dyn_cast<ClosureExpr>(E)) {
159
- checkExistentialInClosureReturnType (Closure, Ctx.Diags );
161
+ if (const ClosureExpr *CE = dyn_cast<ClosureExpr>(E)) {
162
+ checkImplicitCopyReturnType (CE, Ctx.Diags );
163
+ checkExistentialInClosureReturnType (CE, Ctx.Diags );
160
164
}
161
165
162
166
return Action::Continue (E);
@@ -166,14 +170,6 @@ class PerformanceHintDiagnosticWalker final : public ASTWalker {
166
170
if (D->isImplicit ())
167
171
return Action::SkipNode ();
168
172
169
- if (const FuncDecl *FD = dyn_cast<FuncDecl>(D)) {
170
- checkImplicitCopyReturnType (FD, Ctx.Diags );
171
- } else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
172
- checkExistentialInVariableType (VD, Ctx.Diags );
173
- } else if (const TypeAliasDecl *TAD = dyn_cast<TypeAliasDecl>(D)) {
174
- checkExistentialInTypeAlias (TAD, Ctx.Diags );
175
- }
176
-
177
173
return Action::Continue ();
178
174
}
179
175
@@ -182,8 +178,13 @@ class PerformanceHintDiagnosticWalker final : public ASTWalker {
182
178
!D->isImplicit () &&
183
179
" Traversing implicit declarations is disabled in the pre-walk visitor" );
184
180
185
- if (auto *FD = dyn_cast<FuncDecl>(D)) {
181
+ if (const FuncDecl *FD = dyn_cast<FuncDecl>(D)) {
182
+ checkImplicitCopyReturnType (FD, Ctx.Diags );
186
183
checkExistentialInFunctionReturnType (FD, Ctx.Diags );
184
+ } else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
185
+ checkExistentialInVariableType (VD, Ctx.Diags );
186
+ } else if (const TypeAliasDecl *TAD = dyn_cast<TypeAliasDecl>(D)) {
187
+ checkExistentialInTypeAlias (TAD, Ctx.Diags );
187
188
}
188
189
189
190
return Action::Continue ();
0 commit comments