Skip to content

Commit 157a644

Browse files
committed
Handle typed if/case/while-let in VariableTypeCollector
1 parent 1b74379 commit 157a644

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/IDE/IDETypeChecking.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,20 @@ class VariableTypeCollector : public SourceEntityWalker {
808808
auto TyOffset = getTypeOffset(Buffer.str());
809809
bool HasExplicitType =
810810
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+
}
811825
// Add the type information to the result list.
812826
Results.emplace_back(VarOffset, VarLength, HasExplicitType, TyOffset);
813827
}

0 commit comments

Comments
 (0)