@@ -155,8 +155,9 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
155155 if (doIt (typeRepr))
156156 return true ;
157157 for (auto &Inherit : ED->getInherited ()) {
158- if (doIt (Inherit))
159- return true ;
158+ if (auto *const TyR = Inherit.getTypeRepr ())
159+ if (doIt (TyR))
160+ return true ;
160161 }
161162 if (visitTrailingRequirements (ED))
162163 return true ;
@@ -258,9 +259,10 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
258259 }
259260
260261 bool visitAbstractTypeParamDecl (AbstractTypeParamDecl *TPD) {
261- for (auto Inherit: TPD->getInherited ()) {
262- if (doIt (Inherit))
263- return true ;
262+ for (const auto &Inherit: TPD->getInherited ()) {
263+ if (auto *const TyR = Inherit.getTypeRepr ())
264+ if (doIt (TyR))
265+ return true ;
264266 }
265267
266268 if (const auto ATD = dyn_cast<AssociatedTypeDecl>(TPD)) {
@@ -282,9 +284,10 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
282284
283285 bool WalkGenerics = visitGenericParamListIfNeeded (NTD);
284286
285- for (auto &Inherit : NTD->getInherited ()) {
286- if (doIt (Inherit))
287- return true ;
287+ for (const auto &Inherit : NTD->getInherited ()) {
288+ if (auto *const TyR = Inherit.getTypeRepr ())
289+ if (doIt (Inherit.getTypeRepr ()))
290+ return true ;
288291 }
289292
290293 // Visit requirements
@@ -355,8 +358,9 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
355358 bool WalkGenerics = visitGenericParamListIfNeeded (SD);
356359
357360 visit (SD->getIndices ());
358- if (doIt (SD->getElementTypeLoc ()))
359- return true ;
361+ if (auto *const TyR = SD->getElementTypeLoc ().getTypeRepr ())
362+ if (doIt (TyR))
363+ return true ;
360364
361365 // Visit trailing requirements
362366 if (WalkGenerics && visitTrailingRequirements (SD))
@@ -388,10 +392,12 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
388392 visit (PD);
389393 visit (AFD->getParameters ());
390394
391- if (auto *FD = dyn_cast<FuncDecl>(AFD))
395+ if (auto *FD = dyn_cast<FuncDecl>(AFD)) {
392396 if (!isa<AccessorDecl>(FD))
393- if (doIt (FD->getBodyResultTypeLoc ()))
394- return true ;
397+ if (auto *const TyR = FD->getBodyResultTypeLoc ().getTypeRepr ())
398+ if (doIt (TyR))
399+ return true ;
400+ }
395401
396402 // Visit trailing requirements
397403 if (WalkGenerics && visitTrailingRequirements (AFD))
@@ -1320,21 +1326,6 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
13201326 return false ;
13211327 }
13221328
1323- bool doIt (TypeLoc &TL) {
1324- if (!Walker.walkToTypeLocPre (TL))
1325- return false ;
1326-
1327- // No "visit" since TypeLocs are not a class hierarchy. Clients can do what
1328- // they want in walkToTypeLocPre.
1329-
1330- if (auto typerepr = TL.getTypeRepr ())
1331- if (doIt (typerepr))
1332- return true ;
1333-
1334- // If we didn't bail out, do post-order visitation.
1335- return !Walker.walkToTypeLocPost (TL);
1336- }
1337-
13381329 // / Returns true on failure.
13391330 bool doIt (TypeRepr *T) {
13401331 // Do the pre-order visitation. If it returns false, we just
0 commit comments