Skip to content

Commit 1b7b6a3

Browse files
[NFC] Replace other usage of get literal expr description
1 parent ee20fec commit 1b7b6a3

File tree

2 files changed

+4
-30
lines changed

2 files changed

+4
-30
lines changed

lib/AST/Expr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -993,9 +993,9 @@ StringRef LiteralExpr::getLiteralKindDescription() const {
993993
return "nil";
994994
case ExprKind::ObjectLiteral:
995995
return "object";
996-
// Define an unreachable case for all non-literal expressions.
997-
// This way, if a new literal is added in the future, the compiler
998-
// will warn that a case is missing from this switch.
996+
// Define an unreachable case for all non-literal expressions.
997+
// This way, if a new literal is added in the future, the compiler
998+
// will warn that a case is missing from this switch.
999999
#define LITERAL_EXPR(Id, Parent)
10001000
#define EXPR(Id, Parent) case ExprKind::Id:
10011001
#include "swift/AST/ExprNodes.def"

lib/Sema/TypeCheckStmt.cpp

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,34 +1227,8 @@ static bool isDiscardableType(Type type) {
12271227
}
12281228

12291229
static void diagnoseIgnoredLiteral(ASTContext &Ctx, LiteralExpr *LE) {
1230-
const auto getLiteralDescription = [](LiteralExpr *LE) -> StringRef {
1231-
switch (LE->getKind()) {
1232-
case ExprKind::IntegerLiteral: return "integer";
1233-
case ExprKind::FloatLiteral: return "floating-point";
1234-
case ExprKind::BooleanLiteral: return "boolean";
1235-
case ExprKind::StringLiteral: return "string";
1236-
case ExprKind::InterpolatedStringLiteral: return "string";
1237-
case ExprKind::RegexLiteral: return "regular expression";
1238-
case ExprKind::MagicIdentifierLiteral:
1239-
return MagicIdentifierLiteralExpr::getKindString(
1240-
cast<MagicIdentifierLiteralExpr>(LE)->getKind());
1241-
case ExprKind::NilLiteral: return "nil";
1242-
case ExprKind::ObjectLiteral: return "object";
1243-
1244-
// Define an unreachable case for all non-literal expressions.
1245-
// This way, if a new literal is added in the future, the compiler
1246-
// will warn that a case is missing from this switch.
1247-
#define LITERAL_EXPR(Id, Parent)
1248-
#define EXPR(Id, Parent) case ExprKind::Id:
1249-
#include "swift/AST/ExprNodes.def"
1250-
llvm_unreachable("Not a literal expression");
1251-
}
1252-
1253-
llvm_unreachable("Unhandled ExprKind in switch.");
1254-
};
1255-
12561230
Ctx.Diags.diagnose(LE->getLoc(), diag::expression_unused_literal,
1257-
getLiteralDescription(LE))
1231+
LE->getLiteralKindDescription())
12581232
.highlight(LE->getSourceRange());
12591233
}
12601234

0 commit comments

Comments
 (0)