Skip to content

Commit e43cd9d

Browse files
[CSFix] Ajusting contextual type purpose for subscript destination for assign expr in getStructuralTypeContext
1 parent 2e1609e commit e43cd9d

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2989,14 +2989,7 @@ bool TupleContextualFailure::diagnoseAsError() {
29892989
diagnostic = diag::tuple_types_not_convertible_nelts;
29902990
else if ((purpose == CTP_Initialization) && !getContextualType(getAnchor()))
29912991
diagnostic = diag::tuple_types_not_convertible;
2992-
else if (purpose == CTP_AssignSource) {
2993-
auto assignExpr = castToExpr<AssignExpr>(getAnchor());
2994-
if (isa<SubscriptExpr>(assignExpr->getDest())) {
2995-
diagnostic = *getDiagnosticFor(CTP_SubscriptAssignSource, getToType());
2996-
} else {
2997-
diagnostic = *getDiagnosticFor(purpose, getToType());
2998-
}
2999-
} else if (auto diag = getDiagnosticFor(purpose, getToType()))
2992+
else if (auto diag = getDiagnosticFor(purpose, getToType()))
30002993
diagnostic = *diag;
30012994
else
30022995
return false;

lib/Sema/CSFix.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ getStructuralTypeContext(const Solution &solution, ConstraintLocator *locator) {
287287
solution.getType(coerceExpr->getSubExpr()),
288288
solution.getType(coerceExpr));
289289
} else if (auto *assignExpr = getAsExpr<AssignExpr>(locator->getAnchor())) {
290-
return std::make_tuple(CTP_AssignSource,
290+
auto CTP = isa<SubscriptExpr>(assignExpr->getDest()) ? CTP_SubscriptAssignSource
291+
: CTP_AssignSource;
292+
return std::make_tuple(CTP,
291293
solution.getType(assignExpr->getSrc()),
292294
solution.getType(assignExpr->getDest())->getRValueType());
293295
} else if (auto *call = getAsExpr<CallExpr>(locator->getAnchor())) {

0 commit comments

Comments
 (0)