Skip to content

Commit 5eb1df5

Browse files
committed
[CSDiagnostics] NFC: Use std::tie to call resolveImmutableBase
1 parent 9a71f23 commit 5eb1df5

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,9 +1555,9 @@ bool AssignmentFailure::diagnoseAsError() {
15551555

15561556
// Walk through the destination expression, resolving what the problem is. If
15571557
// we find a node in the lvalue path that is problematic, this returns it.
1558-
auto immInfo = resolveImmutableBase(DestExpr);
1559-
1560-
Optional<OverloadChoice> choice = immInfo.second;
1558+
Expr *immutableExpr;
1559+
Optional<OverloadChoice> choice;
1560+
std::tie(immutableExpr, choice) = resolveImmutableBase(DestExpr);
15611561

15621562
// Attempt diagnostics based on the overload choice.
15631563
if (choice.hasValue()) {
@@ -1571,17 +1571,17 @@ bool AssignmentFailure::diagnoseAsError() {
15711571

15721572
if (!choice->isDecl()) {
15731573
if (choice->getKind() == OverloadChoiceKind::KeyPathApplication &&
1574-
!isa<ApplyExpr>(immInfo.first)) {
1574+
!isa<ApplyExpr>(immutableExpr)) {
15751575
std::string message = "key path is read-only";
1576-
if (auto *SE = dyn_cast<SubscriptExpr>(immInfo.first)) {
1576+
if (auto *SE = dyn_cast<SubscriptExpr>(immutableExpr)) {
15771577
if (auto *DRE = dyn_cast<DeclRefExpr>(getKeyPathArgument(SE))) {
15781578
auto identifier = DRE->getDecl()->getBaseName().getIdentifier();
15791579
message =
15801580
"'" + identifier.str().str() + "' is a read-only key path";
15811581
}
15821582
}
15831583
emitDiagnostic(Loc, DeclDiagnostic, message)
1584-
.highlight(immInfo.first->getSourceRange());
1584+
.highlight(immutableExpr->getSourceRange());
15851585
return true;
15861586
}
15871587
return false;
@@ -1595,7 +1595,7 @@ bool AssignmentFailure::diagnoseAsError() {
15951595
message += VD->getName().str().str();
15961596
message += "'";
15971597

1598-
auto type = getType(immInfo.first);
1598+
auto type = getType(immutableExpr);
15991599

16001600
if (isKnownKeyPathType(type))
16011601
message += " is read-only";
@@ -1614,7 +1614,7 @@ bool AssignmentFailure::diagnoseAsError() {
16141614
}
16151615

16161616
emitDiagnostic(Loc, DeclDiagnostic, message)
1617-
.highlight(immInfo.first->getSourceRange());
1617+
.highlight(immutableExpr->getSourceRange());
16181618

16191619
// If there is a masked instance variable of the same type, emit a
16201620
// note to fixit prepend a 'self.'.
@@ -1654,7 +1654,7 @@ bool AssignmentFailure::diagnoseAsError() {
16541654
message = "subscript is immutable";
16551655

16561656
emitDiagnostic(Loc, DeclDiagnostic, message)
1657-
.highlight(immInfo.first->getSourceRange());
1657+
.highlight(immutableExpr->getSourceRange());
16581658
return true;
16591659
}
16601660

@@ -1676,7 +1676,7 @@ bool AssignmentFailure::diagnoseAsError() {
16761676
message += " is not settable";
16771677

16781678
emitDiagnostic(Loc, diagID, message)
1679-
.highlight(immInfo.first->getSourceRange());
1679+
.highlight(immutableExpr->getSourceRange());
16801680
return true;
16811681
}
16821682
}
@@ -1686,21 +1686,21 @@ bool AssignmentFailure::diagnoseAsError() {
16861686

16871687
// If a keypath was the problem but wasn't resolved into a vardecl
16881688
// it is ambiguous or unable to be used for setting.
1689-
if (auto *KPE = dyn_cast_or_null<KeyPathExpr>(immInfo.first)) {
1689+
if (auto *KPE = dyn_cast_or_null<KeyPathExpr>(immutableExpr)) {
16901690
emitDiagnostic(Loc, DeclDiagnostic, "immutable key path")
16911691
.highlight(KPE->getSourceRange());
16921692
return true;
16931693
}
16941694

1695-
if (auto LE = dyn_cast<LiteralExpr>(immInfo.first)) {
1695+
if (auto LE = dyn_cast<LiteralExpr>(immutableExpr)) {
16961696
emitDiagnostic(Loc, DeclDiagnostic, "literals are not mutable")
16971697
.highlight(LE->getSourceRange());
16981698
return true;
16991699
}
17001700

17011701
// If the expression is the result of a call, it is an rvalue, not a mutable
17021702
// lvalue.
1703-
if (auto *AE = dyn_cast<ApplyExpr>(immInfo.first)) {
1703+
if (auto *AE = dyn_cast<ApplyExpr>(immutableExpr)) {
17041704
// Handle literals, which are a call to the conversion function.
17051705
auto argsTuple =
17061706
dyn_cast<TupleExpr>(AE->getArg()->getSemanticsProvidingExpr());
@@ -1733,22 +1733,22 @@ bool AssignmentFailure::diagnoseAsError() {
17331733
return true;
17341734
}
17351735

1736-
if (auto contextualType = cs.getContextualType(immInfo.first)) {
1736+
if (auto contextualType = cs.getContextualType(immutableExpr)) {
17371737
Type neededType = contextualType->getInOutObjectType();
1738-
Type actualType = getType(immInfo.first)->getInOutObjectType();
1738+
Type actualType = getType(immutableExpr)->getInOutObjectType();
17391739
if (!neededType->isEqual(actualType)) {
17401740
if (DeclDiagnostic.ID != diag::cannot_pass_rvalue_inout_subelement.ID) {
17411741
emitDiagnostic(Loc, DeclDiagnostic,
17421742
"implicit conversion from '" + actualType->getString() +
17431743
"' to '" + neededType->getString() +
17441744
"' requires a temporary")
1745-
.highlight(immInfo.first->getSourceRange());
1745+
.highlight(immutableExpr->getSourceRange());
17461746
}
17471747
return true;
17481748
}
17491749
}
17501750

1751-
if (auto IE = dyn_cast<IfExpr>(immInfo.first)) {
1751+
if (auto IE = dyn_cast<IfExpr>(immutableExpr)) {
17521752
emitDiagnostic(Loc, DeclDiagnostic,
17531753
"result of conditional operator '? :' is never mutable")
17541754
.highlight(IE->getQuestionLoc())
@@ -1757,7 +1757,7 @@ bool AssignmentFailure::diagnoseAsError() {
17571757
}
17581758

17591759
emitDiagnostic(Loc, TypeDiagnostic, getType(DestExpr))
1760-
.highlight(immInfo.first->getSourceRange());
1760+
.highlight(immutableExpr->getSourceRange());
17611761
return true;
17621762
}
17631763

0 commit comments

Comments
 (0)