@@ -1555,9 +1555,9 @@ bool AssignmentFailure::diagnoseAsError() {
1555
1555
1556
1556
// Walk through the destination expression, resolving what the problem is. If
1557
1557
// 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) ;
1561
1561
1562
1562
// Attempt diagnostics based on the overload choice.
1563
1563
if (choice.hasValue ()) {
@@ -1571,17 +1571,17 @@ bool AssignmentFailure::diagnoseAsError() {
1571
1571
1572
1572
if (!choice->isDecl ()) {
1573
1573
if (choice->getKind () == OverloadChoiceKind::KeyPathApplication &&
1574
- !isa<ApplyExpr>(immInfo. first )) {
1574
+ !isa<ApplyExpr>(immutableExpr )) {
1575
1575
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 )) {
1577
1577
if (auto *DRE = dyn_cast<DeclRefExpr>(getKeyPathArgument (SE))) {
1578
1578
auto identifier = DRE->getDecl ()->getBaseName ().getIdentifier ();
1579
1579
message =
1580
1580
" '" + identifier.str ().str () + " ' is a read-only key path" ;
1581
1581
}
1582
1582
}
1583
1583
emitDiagnostic (Loc, DeclDiagnostic, message)
1584
- .highlight (immInfo. first ->getSourceRange ());
1584
+ .highlight (immutableExpr ->getSourceRange ());
1585
1585
return true ;
1586
1586
}
1587
1587
return false ;
@@ -1595,7 +1595,7 @@ bool AssignmentFailure::diagnoseAsError() {
1595
1595
message += VD->getName ().str ().str ();
1596
1596
message += " '" ;
1597
1597
1598
- auto type = getType (immInfo. first );
1598
+ auto type = getType (immutableExpr );
1599
1599
1600
1600
if (isKnownKeyPathType (type))
1601
1601
message += " is read-only" ;
@@ -1614,7 +1614,7 @@ bool AssignmentFailure::diagnoseAsError() {
1614
1614
}
1615
1615
1616
1616
emitDiagnostic (Loc, DeclDiagnostic, message)
1617
- .highlight (immInfo. first ->getSourceRange ());
1617
+ .highlight (immutableExpr ->getSourceRange ());
1618
1618
1619
1619
// If there is a masked instance variable of the same type, emit a
1620
1620
// note to fixit prepend a 'self.'.
@@ -1654,7 +1654,7 @@ bool AssignmentFailure::diagnoseAsError() {
1654
1654
message = " subscript is immutable" ;
1655
1655
1656
1656
emitDiagnostic (Loc, DeclDiagnostic, message)
1657
- .highlight (immInfo. first ->getSourceRange ());
1657
+ .highlight (immutableExpr ->getSourceRange ());
1658
1658
return true ;
1659
1659
}
1660
1660
@@ -1676,7 +1676,7 @@ bool AssignmentFailure::diagnoseAsError() {
1676
1676
message += " is not settable" ;
1677
1677
1678
1678
emitDiagnostic (Loc, diagID, message)
1679
- .highlight (immInfo. first ->getSourceRange ());
1679
+ .highlight (immutableExpr ->getSourceRange ());
1680
1680
return true ;
1681
1681
}
1682
1682
}
@@ -1686,21 +1686,21 @@ bool AssignmentFailure::diagnoseAsError() {
1686
1686
1687
1687
// If a keypath was the problem but wasn't resolved into a vardecl
1688
1688
// 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 )) {
1690
1690
emitDiagnostic (Loc, DeclDiagnostic, " immutable key path" )
1691
1691
.highlight (KPE->getSourceRange ());
1692
1692
return true ;
1693
1693
}
1694
1694
1695
- if (auto LE = dyn_cast<LiteralExpr>(immInfo. first )) {
1695
+ if (auto LE = dyn_cast<LiteralExpr>(immutableExpr )) {
1696
1696
emitDiagnostic (Loc, DeclDiagnostic, " literals are not mutable" )
1697
1697
.highlight (LE->getSourceRange ());
1698
1698
return true ;
1699
1699
}
1700
1700
1701
1701
// If the expression is the result of a call, it is an rvalue, not a mutable
1702
1702
// lvalue.
1703
- if (auto *AE = dyn_cast<ApplyExpr>(immInfo. first )) {
1703
+ if (auto *AE = dyn_cast<ApplyExpr>(immutableExpr )) {
1704
1704
// Handle literals, which are a call to the conversion function.
1705
1705
auto argsTuple =
1706
1706
dyn_cast<TupleExpr>(AE->getArg ()->getSemanticsProvidingExpr ());
@@ -1733,22 +1733,22 @@ bool AssignmentFailure::diagnoseAsError() {
1733
1733
return true ;
1734
1734
}
1735
1735
1736
- if (auto contextualType = cs.getContextualType (immInfo. first )) {
1736
+ if (auto contextualType = cs.getContextualType (immutableExpr )) {
1737
1737
Type neededType = contextualType->getInOutObjectType ();
1738
- Type actualType = getType (immInfo. first )->getInOutObjectType ();
1738
+ Type actualType = getType (immutableExpr )->getInOutObjectType ();
1739
1739
if (!neededType->isEqual (actualType)) {
1740
1740
if (DeclDiagnostic.ID != diag::cannot_pass_rvalue_inout_subelement.ID ) {
1741
1741
emitDiagnostic (Loc, DeclDiagnostic,
1742
1742
" implicit conversion from '" + actualType->getString () +
1743
1743
" ' to '" + neededType->getString () +
1744
1744
" ' requires a temporary" )
1745
- .highlight (immInfo. first ->getSourceRange ());
1745
+ .highlight (immutableExpr ->getSourceRange ());
1746
1746
}
1747
1747
return true ;
1748
1748
}
1749
1749
}
1750
1750
1751
- if (auto IE = dyn_cast<IfExpr>(immInfo. first )) {
1751
+ if (auto IE = dyn_cast<IfExpr>(immutableExpr )) {
1752
1752
emitDiagnostic (Loc, DeclDiagnostic,
1753
1753
" result of conditional operator '? :' is never mutable" )
1754
1754
.highlight (IE->getQuestionLoc ())
@@ -1757,7 +1757,7 @@ bool AssignmentFailure::diagnoseAsError() {
1757
1757
}
1758
1758
1759
1759
emitDiagnostic (Loc, TypeDiagnostic, getType (DestExpr))
1760
- .highlight (immInfo. first ->getSourceRange ());
1760
+ .highlight (immutableExpr ->getSourceRange ());
1761
1761
return true ;
1762
1762
}
1763
1763
0 commit comments