Skip to content

Commit 6028bfb

Browse files
authored
Merge pull request #70903 from xedin/fix-is-subscript-result-type-to-account-keypath
[ConstraintSystem] Teach `isSubscriptResultType` about subscripts in …
2 parents 8b66f23 + 5e1659c commit 6028bfb

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,24 @@ bool TypeVariableType::Implementation::isSubscriptResultType() const {
161161
if (!(locator && locator->getAnchor()))
162162
return false;
163163

164-
return isExpr<SubscriptExpr>(locator->getAnchor()) &&
165-
locator->isLastElement<LocatorPathElt::FunctionResult>();
164+
if (!locator->isLastElement<LocatorPathElt::FunctionResult>())
165+
return false;
166+
167+
if (isExpr<SubscriptExpr>(locator->getAnchor()))
168+
return true;
169+
170+
auto *KP = getAsExpr<KeyPathExpr>(locator->getAnchor());
171+
if (!KP)
172+
return false;
173+
174+
auto componentLoc = locator->findFirst<LocatorPathElt::KeyPathComponent>();
175+
if (!componentLoc)
176+
return false;
177+
178+
auto &component = KP->getComponents()[componentLoc->getIndex()];
179+
return component.getKind() == KeyPathExpr::Component::Kind::Subscript ||
180+
component.getKind() ==
181+
KeyPathExpr::Component::Kind::UnresolvedSubscript;
166182
}
167183

168184
bool TypeVariableType::Implementation::isParameterPack() const {

0 commit comments

Comments
 (0)