File tree Expand file tree Collapse file tree 2 files changed +18
-19
lines changed Expand file tree Collapse file tree 2 files changed +18
-19
lines changed Original file line number Diff line number Diff line change @@ -5806,11 +5806,24 @@ void VarDecl::setNamingPattern(NamedPattern *Pat) {
5806
5806
}
5807
5807
5808
5808
TypeRepr *VarDecl::getTypeReprOrParentPatternTypeRepr () const {
5809
- if (auto *param = dyn_cast<ParamDecl>(this ))
5810
- return param->getTypeRepr ();
5811
-
5812
- if (auto *parentPattern = dyn_cast_or_null<TypedPattern>(getParentPattern ()))
5813
- return parentPattern->getTypeRepr ();
5809
+ if (auto *Param = dyn_cast<ParamDecl>(this ))
5810
+ return Param->getTypeRepr ();
5811
+
5812
+ auto *ParentPattern = getParentPattern ();
5813
+
5814
+ if (auto *TyPattern = dyn_cast_or_null<TypedPattern>(ParentPattern))
5815
+ return TyPattern->getTypeRepr ();
5816
+
5817
+ // Handle typed if/guard/while-let as a special case (e.g. `if let x: Int
5818
+ // = Optional.some(4)`), since the `TypedPattern` is not the top-level
5819
+ // pattern here - instead it is an implicit `OptionalSomePattern`
5820
+ if (auto *SomePattern =
5821
+ dyn_cast_or_null<OptionalSomePattern>(ParentPattern)) {
5822
+ if (auto *TyPattern =
5823
+ dyn_cast<TypedPattern>(SomePattern->getSubPattern ())) {
5824
+ return TyPattern->getTypeRepr ();
5825
+ }
5826
+ }
5814
5827
5815
5828
return nullptr ;
5816
5829
}
Original file line number Diff line number Diff line change @@ -808,20 +808,6 @@ class VariableTypeCollector : public SourceEntityWalker {
808
808
auto TyOffset = getTypeOffset (Buffer.str ());
809
809
bool HasExplicitType =
810
810
VD->getTypeReprOrParentPatternTypeRepr () != nullptr ;
811
- // Handle typed if/guard/while-let as a special case (e.g. `if let x: Int
812
- // = Optional.some(4)`), since the `TypedPattern` is not the top-level
813
- // pattern here - instead it is an implicit `OptionalSomePattern`
814
- if (!HasExplicitType) {
815
- if (auto *somePattern =
816
- dyn_cast_or_null<OptionalSomePattern>(VD->getParentPattern ())) {
817
- if (somePattern->isImplicit ()) {
818
- if (auto *typedPattern =
819
- dyn_cast<TypedPattern>(somePattern->getSubPattern ())) {
820
- HasExplicitType = typedPattern->getTypeRepr () != nullptr ;
821
- }
822
- }
823
- }
824
- }
825
811
// Add the type information to the result list.
826
812
Results.emplace_back (VarOffset, VarLength, HasExplicitType, TyOffset);
827
813
}
You can’t perform that action at this time.
0 commit comments