Skip to content

Commit 8fca2c5

Browse files
committed
[CSDiagnostics] Look into tuple expressions to find requirement failure location
If the requirement failure is related to an assignment destination analyze the source of the assignment and if it's a tuple, find the element and return its type.
1 parent 890e45d commit 8fca2c5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,17 @@ Type RequirementFailure::getOwnerType() const {
242242
// to convert source to destination, which means that
243243
// owner type is actually not an assignment expression
244244
// itself but its source.
245-
if (auto *assignment = getAsExpr<AssignExpr>(anchor))
245+
if (auto *assignment = getAsExpr<AssignExpr>(anchor)) {
246246
anchor = assignment->getSrc();
247+
// If locator points to a tuple element, let's dig that up.
248+
// Situations like `<<dest>> = (v, 2)` where `v` has a requirement failure.
249+
if (auto tupleEltIdx =
250+
getLocator()->findFirst<LocatorPathElt::AnyTupleElement>()) {
251+
if (auto *tuple = getAsExpr<TupleExpr>(anchor)) {
252+
return getType(tuple->getElement(tupleEltIdx->getIndex()));
253+
}
254+
}
255+
}
247256

248257
return getType(anchor)->getInOutObjectType()->getMetatypeInstanceType();
249258
}

0 commit comments

Comments
 (0)