@@ -1154,15 +1154,17 @@ namespace {
1154
1154
return finish (true , expr);
1155
1155
1156
1156
if (isa<SubscriptExpr>(call->getSecond ())) {
1157
- TC.diagnose (expr->getStartLoc (),
1158
- diag::cannot_pass_inout_arg_to_subscript);
1157
+ getASTContext ().Diags .diagnose (
1158
+ expr->getStartLoc (),
1159
+ diag::cannot_pass_inout_arg_to_subscript);
1159
1160
return finish (false , nullptr );
1160
1161
}
1161
1162
}
1162
1163
}
1163
1164
}
1164
1165
1165
- TC.diagnose (expr->getStartLoc (), diag::extraneous_address_of);
1166
+ getASTContext ().Diags .diagnose (expr->getStartLoc (),
1167
+ diag::extraneous_address_of);
1166
1168
return finish (false , nullptr );
1167
1169
}
1168
1170
@@ -1648,7 +1650,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
1648
1650
if (auto *AE = dyn_cast<ArrowExpr>(E)) {
1649
1651
if (!AE->isFolded ()) return nullptr ;
1650
1652
1651
- auto diagnoseMissingParens = [](TypeChecker &TC , TypeRepr *tyR) {
1653
+ auto diagnoseMissingParens = [](DiagnosticEngine &DE , TypeRepr *tyR) {
1652
1654
bool isVoid = false ;
1653
1655
if (const auto Void = dyn_cast<SimpleIdentTypeRepr>(tyR)) {
1654
1656
if (Void->getIdentifier ().str () == " Void" ) {
@@ -1657,24 +1659,25 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
1657
1659
}
1658
1660
1659
1661
if (isVoid) {
1660
- TC .diagnose (tyR->getStartLoc (), diag::function_type_no_parens)
1662
+ DE .diagnose (tyR->getStartLoc (), diag::function_type_no_parens)
1661
1663
.fixItReplace (tyR->getStartLoc (), " ()" );
1662
1664
} else {
1663
- TC .diagnose (tyR->getStartLoc (), diag::function_type_no_parens)
1665
+ DE .diagnose (tyR->getStartLoc (), diag::function_type_no_parens)
1664
1666
.highlight (tyR->getSourceRange ())
1665
1667
.fixItInsert (tyR->getStartLoc (), " (" )
1666
1668
.fixItInsertAfter (tyR->getEndLoc (), " )" );
1667
1669
}
1668
1670
};
1669
1671
1672
+ auto &DE = getASTContext ().Diags ;
1670
1673
auto extractInputTypeRepr = [&](Expr *E) -> TupleTypeRepr * {
1671
1674
if (!E)
1672
1675
return nullptr ;
1673
1676
if (auto *TyE = dyn_cast<TypeExpr>(E)) {
1674
1677
auto ArgRepr = TyE->getTypeRepr ();
1675
1678
if (auto *TTyRepr = dyn_cast<TupleTypeRepr>(ArgRepr))
1676
1679
return TTyRepr;
1677
- diagnoseMissingParens (TC , ArgRepr);
1680
+ diagnoseMissingParens (DE , ArgRepr);
1678
1681
return TupleTypeRepr::create (getASTContext (), {ArgRepr},
1679
1682
ArgRepr->getSourceRange ());
1680
1683
}
@@ -1689,7 +1692,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
1689
1692
auto ArgRepr = ArgsTypeExpr->getTypeRepr ();
1690
1693
if (auto *TTyRepr = dyn_cast<TupleTypeRepr>(ArgRepr))
1691
1694
return TTyRepr;
1692
- diagnoseMissingParens (TC , ArgRepr);
1695
+ diagnoseMissingParens (DE , ArgRepr);
1693
1696
return TupleTypeRepr::create (getASTContext (), {ArgRepr},
1694
1697
ArgRepr->getSourceRange ());
1695
1698
}
@@ -1715,7 +1718,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
1715
1718
1716
1719
TupleTypeRepr *ArgsTypeRepr = extractInputTypeRepr (AE->getArgsExpr ());
1717
1720
if (!ArgsTypeRepr) {
1718
- TC .diagnose (AE->getArgsExpr ()->getLoc (),
1721
+ DE .diagnose (AE->getArgsExpr ()->getLoc (),
1719
1722
diag::expected_type_before_arrow);
1720
1723
auto ArgRange = AE->getArgsExpr ()->getSourceRange ();
1721
1724
auto ErrRepr = new (getASTContext ()) ErrorTypeRepr (ArgRange);
@@ -1725,7 +1728,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
1725
1728
1726
1729
TypeRepr *ResultTypeRepr = extractTypeRepr (AE->getResultExpr ());
1727
1730
if (!ResultTypeRepr) {
1728
- TC .diagnose (AE->getResultExpr ()->getLoc (),
1731
+ DE .diagnose (AE->getResultExpr ()->getLoc (),
1729
1732
diag::expected_type_after_arrow);
1730
1733
ResultTypeRepr = new (getASTContext ())
1731
1734
ErrorTypeRepr (AE->getResultExpr ()->getSourceRange ());
@@ -1802,6 +1805,7 @@ void PreCheckExpression::resolveKeyPathExpr(KeyPathExpr *KPE) {
1802
1805
1803
1806
TypeRepr *rootType = nullptr ;
1804
1807
SmallVector<KeyPathExpr::Component, 4 > components;
1808
+ auto &DE = getASTContext ().Diags ;
1805
1809
1806
1810
// Pre-order visit of a sequence foo.bar[0]?.baz, which means that the
1807
1811
// components are pushed in reverse order.
@@ -1863,10 +1867,10 @@ void PreCheckExpression::resolveKeyPathExpr(KeyPathExpr *KPE) {
1863
1867
// \(<expr>) may be an attempt to write a string interpolation outside
1864
1868
// of a string literal; diagnose this case specially.
1865
1869
if (isa<ParenExpr>(expr) || isa<TupleExpr>(expr)) {
1866
- TC .diagnose (expr->getLoc (),
1870
+ DE .diagnose (expr->getLoc (),
1867
1871
diag::expr_string_interpolation_outside_string);
1868
1872
} else {
1869
- TC .diagnose (expr->getLoc (),
1873
+ DE .diagnose (expr->getLoc (),
1870
1874
diag::expr_swift_keypath_invalid_component);
1871
1875
}
1872
1876
}
@@ -1890,7 +1894,7 @@ void PreCheckExpression::resolveKeyPathExpr(KeyPathExpr *KPE) {
1890
1894
} else {
1891
1895
// FIXME: Probably better to catch this case earlier and force-eval as
1892
1896
// TypeExpr.
1893
- TC .diagnose (root->getLoc (),
1897
+ DE .diagnose (root->getLoc (),
1894
1898
diag::expr_swift_keypath_not_starting_with_type);
1895
1899
1896
1900
// Traverse this path for recovery purposes: it may be a typo like
@@ -1905,7 +1909,7 @@ void PreCheckExpression::resolveKeyPathExpr(KeyPathExpr *KPE) {
1905
1909
1906
1910
// Key paths must be spelled with at least one component.
1907
1911
if (components.empty ()) {
1908
- TC .diagnose (KPE->getLoc (), diag::expr_swift_keypath_empty);
1912
+ DE .diagnose (KPE->getLoc (), diag::expr_swift_keypath_empty);
1909
1913
// Passes further down the pipeline expect keypaths to always have at least
1910
1914
// one component, so stuff an invalid component in the AST for recovery.
1911
1915
components.push_back (KeyPathExpr::Component ());
@@ -1920,7 +1924,7 @@ void PreCheckExpression::resolveKeyPathExpr(KeyPathExpr *KPE) {
1920
1924
Expr *PreCheckExpression::simplifyTypeConstructionWithLiteralArg (Expr *E) {
1921
1925
// If constructor call is expected to produce an optional let's not attempt
1922
1926
// this optimization because literal initializers aren't failable.
1923
- if (!TC. getLangOpts () .isSwiftVersionAtLeast (5 )) {
1927
+ if (!getASTContext (). LangOpts .isSwiftVersionAtLeast (5 )) {
1924
1928
if (!ExprStack.empty ()) {
1925
1929
auto *parent = ExprStack.back ();
1926
1930
if (isa<BindOptionalExpr>(parent) || isa<ForceValueExpr>(parent))
0 commit comments