@@ -1668,36 +1668,35 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
1668
1668
if (auto *AE = dyn_cast<ArrowExpr>(E)) {
1669
1669
if (!AE->isFolded ()) return nullptr ;
1670
1670
1671
- auto diagnoseMissingParens = [](DiagnosticEngine &DE , TypeRepr *tyR) {
1671
+ auto diagnoseMissingParens = [](ASTContext &ctx , TypeRepr *tyR) {
1672
1672
bool isVoid = false ;
1673
1673
if (const auto Void = dyn_cast<SimpleIdentTypeRepr>(tyR)) {
1674
- if (Void->getIdentifier (). str () == " Void " ) {
1674
+ if (Void->getIdentifier () == ctx. Id_Void ) {
1675
1675
isVoid = true ;
1676
1676
}
1677
1677
}
1678
1678
1679
1679
if (isVoid) {
1680
- DE .diagnose (tyR->getStartLoc (), diag::function_type_no_parens)
1680
+ ctx. Diags .diagnose (tyR->getStartLoc (), diag::function_type_no_parens)
1681
1681
.fixItReplace (tyR->getStartLoc (), " ()" );
1682
1682
} else {
1683
- DE .diagnose (tyR->getStartLoc (), diag::function_type_no_parens)
1683
+ ctx. Diags .diagnose (tyR->getStartLoc (), diag::function_type_no_parens)
1684
1684
.highlight (tyR->getSourceRange ())
1685
1685
.fixItInsert (tyR->getStartLoc (), " (" )
1686
1686
.fixItInsertAfter (tyR->getEndLoc (), " )" );
1687
1687
}
1688
1688
};
1689
1689
1690
- auto &DE = getASTContext (). Diags ;
1690
+ auto &ctx = getASTContext ();
1691
1691
auto extractInputTypeRepr = [&](Expr *E) -> TupleTypeRepr * {
1692
1692
if (!E)
1693
1693
return nullptr ;
1694
1694
if (auto *TyE = dyn_cast<TypeExpr>(E)) {
1695
1695
auto ArgRepr = TyE->getTypeRepr ();
1696
1696
if (auto *TTyRepr = dyn_cast<TupleTypeRepr>(ArgRepr))
1697
1697
return TTyRepr;
1698
- diagnoseMissingParens (DE, ArgRepr);
1699
- return TupleTypeRepr::create (getASTContext (), {ArgRepr},
1700
- ArgRepr->getSourceRange ());
1698
+ diagnoseMissingParens (ctx, ArgRepr);
1699
+ return TupleTypeRepr::create (ctx, {ArgRepr}, ArgRepr->getSourceRange ());
1701
1700
}
1702
1701
if (auto *TE = dyn_cast<TupleExpr>(E))
1703
1702
if (TE->getNumElements () == 0 )
@@ -1710,9 +1709,8 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
1710
1709
auto ArgRepr = ArgsTypeExpr->getTypeRepr ();
1711
1710
if (auto *TTyRepr = dyn_cast<TupleTypeRepr>(ArgRepr))
1712
1711
return TTyRepr;
1713
- diagnoseMissingParens (DE, ArgRepr);
1714
- return TupleTypeRepr::create (getASTContext (), {ArgRepr},
1715
- ArgRepr->getSourceRange ());
1712
+ diagnoseMissingParens (ctx, ArgRepr);
1713
+ return TupleTypeRepr::create (ctx, {ArgRepr}, ArgRepr->getSourceRange ());
1716
1714
}
1717
1715
return nullptr ;
1718
1716
};
@@ -1724,8 +1722,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
1724
1722
return TyE->getTypeRepr ();
1725
1723
if (auto *TE = dyn_cast<TupleExpr>(E))
1726
1724
if (TE->getNumElements () == 0 )
1727
- return TupleTypeRepr::createEmpty (getASTContext (),
1728
- TE->getSourceRange ());
1725
+ return TupleTypeRepr::createEmpty (ctx, TE->getSourceRange ());
1729
1726
1730
1727
// When simplifying a type expr like "P1 & P2 -> P3 & P4 -> Int",
1731
1728
// it may have been folded at the same time; recursively simplify it.
@@ -1736,26 +1733,26 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
1736
1733
1737
1734
TupleTypeRepr *ArgsTypeRepr = extractInputTypeRepr (AE->getArgsExpr ());
1738
1735
if (!ArgsTypeRepr) {
1739
- DE .diagnose (AE->getArgsExpr ()->getLoc (),
1740
- diag::expected_type_before_arrow);
1736
+ ctx. Diags .diagnose (AE->getArgsExpr ()->getLoc (),
1737
+ diag::expected_type_before_arrow);
1741
1738
auto ArgRange = AE->getArgsExpr ()->getSourceRange ();
1742
- auto ErrRepr = new (getASTContext () ) ErrorTypeRepr (ArgRange);
1739
+ auto ErrRepr = new (ctx ) ErrorTypeRepr (ArgRange);
1743
1740
ArgsTypeRepr =
1744
- TupleTypeRepr::create (getASTContext () , {ErrRepr}, ArgRange);
1741
+ TupleTypeRepr::create (ctx , {ErrRepr}, ArgRange);
1745
1742
}
1746
1743
1747
1744
TypeRepr *ResultTypeRepr = extractTypeRepr (AE->getResultExpr ());
1748
1745
if (!ResultTypeRepr) {
1749
- DE .diagnose (AE->getResultExpr ()->getLoc (),
1750
- diag::expected_type_after_arrow);
1751
- ResultTypeRepr = new (getASTContext () )
1746
+ ctx. Diags .diagnose (AE->getResultExpr ()->getLoc (),
1747
+ diag::expected_type_after_arrow);
1748
+ ResultTypeRepr = new (ctx )
1752
1749
ErrorTypeRepr (AE->getResultExpr ()->getSourceRange ());
1753
1750
}
1754
1751
1755
- auto NewTypeRepr = new (getASTContext () )
1752
+ auto NewTypeRepr = new (ctx )
1756
1753
FunctionTypeRepr (nullptr , ArgsTypeRepr, AE->getThrowsLoc (),
1757
1754
AE->getArrowLoc (), ResultTypeRepr);
1758
- return new (getASTContext () ) TypeExpr (TypeLoc (NewTypeRepr, Type ()));
1755
+ return new (ctx ) TypeExpr (TypeLoc (NewTypeRepr, Type ()));
1759
1756
}
1760
1757
1761
1758
// Fold 'P & Q' into a composition type
0 commit comments