Skip to content

Commit 93b9c0b

Browse files
committed
[NFC] Use ASTContext::Id_Void constant in simplifyTypeExpr check
1 parent a3035eb commit 93b9c0b

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,36 +1668,35 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
16681668
if (auto *AE = dyn_cast<ArrowExpr>(E)) {
16691669
if (!AE->isFolded()) return nullptr;
16701670

1671-
auto diagnoseMissingParens = [](DiagnosticEngine &DE, TypeRepr *tyR) {
1671+
auto diagnoseMissingParens = [](ASTContext &ctx, TypeRepr *tyR) {
16721672
bool isVoid = false;
16731673
if (const auto Void = dyn_cast<SimpleIdentTypeRepr>(tyR)) {
1674-
if (Void->getIdentifier().str() == "Void") {
1674+
if (Void->getIdentifier() == ctx.Id_Void) {
16751675
isVoid = true;
16761676
}
16771677
}
16781678

16791679
if (isVoid) {
1680-
DE.diagnose(tyR->getStartLoc(), diag::function_type_no_parens)
1680+
ctx.Diags.diagnose(tyR->getStartLoc(), diag::function_type_no_parens)
16811681
.fixItReplace(tyR->getStartLoc(), "()");
16821682
} else {
1683-
DE.diagnose(tyR->getStartLoc(), diag::function_type_no_parens)
1683+
ctx.Diags.diagnose(tyR->getStartLoc(), diag::function_type_no_parens)
16841684
.highlight(tyR->getSourceRange())
16851685
.fixItInsert(tyR->getStartLoc(), "(")
16861686
.fixItInsertAfter(tyR->getEndLoc(), ")");
16871687
}
16881688
};
16891689

1690-
auto &DE = getASTContext().Diags;
1690+
auto &ctx = getASTContext();
16911691
auto extractInputTypeRepr = [&](Expr *E) -> TupleTypeRepr * {
16921692
if (!E)
16931693
return nullptr;
16941694
if (auto *TyE = dyn_cast<TypeExpr>(E)) {
16951695
auto ArgRepr = TyE->getTypeRepr();
16961696
if (auto *TTyRepr = dyn_cast<TupleTypeRepr>(ArgRepr))
16971697
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());
17011700
}
17021701
if (auto *TE = dyn_cast<TupleExpr>(E))
17031702
if (TE->getNumElements() == 0)
@@ -1710,9 +1709,8 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
17101709
auto ArgRepr = ArgsTypeExpr->getTypeRepr();
17111710
if (auto *TTyRepr = dyn_cast<TupleTypeRepr>(ArgRepr))
17121711
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());
17161714
}
17171715
return nullptr;
17181716
};
@@ -1724,8 +1722,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
17241722
return TyE->getTypeRepr();
17251723
if (auto *TE = dyn_cast<TupleExpr>(E))
17261724
if (TE->getNumElements() == 0)
1727-
return TupleTypeRepr::createEmpty(getASTContext(),
1728-
TE->getSourceRange());
1725+
return TupleTypeRepr::createEmpty(ctx, TE->getSourceRange());
17291726

17301727
// When simplifying a type expr like "P1 & P2 -> P3 & P4 -> Int",
17311728
// it may have been folded at the same time; recursively simplify it.
@@ -1736,26 +1733,26 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
17361733

17371734
TupleTypeRepr *ArgsTypeRepr = extractInputTypeRepr(AE->getArgsExpr());
17381735
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);
17411738
auto ArgRange = AE->getArgsExpr()->getSourceRange();
1742-
auto ErrRepr = new (getASTContext()) ErrorTypeRepr(ArgRange);
1739+
auto ErrRepr = new (ctx) ErrorTypeRepr(ArgRange);
17431740
ArgsTypeRepr =
1744-
TupleTypeRepr::create(getASTContext(), {ErrRepr}, ArgRange);
1741+
TupleTypeRepr::create(ctx, {ErrRepr}, ArgRange);
17451742
}
17461743

17471744
TypeRepr *ResultTypeRepr = extractTypeRepr(AE->getResultExpr());
17481745
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)
17521749
ErrorTypeRepr(AE->getResultExpr()->getSourceRange());
17531750
}
17541751

1755-
auto NewTypeRepr = new (getASTContext())
1752+
auto NewTypeRepr = new (ctx)
17561753
FunctionTypeRepr(nullptr, ArgsTypeRepr, AE->getThrowsLoc(),
17571754
AE->getArrowLoc(), ResultTypeRepr);
1758-
return new (getASTContext()) TypeExpr(TypeLoc(NewTypeRepr, Type()));
1755+
return new (ctx) TypeExpr(TypeLoc(NewTypeRepr, Type()));
17591756
}
17601757

17611758
// Fold 'P & Q' into a composition type

0 commit comments

Comments
 (0)