Apply a digit limit for all getAsInteger calls (#1117)

In particular noticed the issue in type literal parsing, but given this has come up once before, trying to address it consistently.
This commit is contained in:
Jon Meow
2022-03-03 12:26:04 -08:00
committed by GitHub
parent b41dfb2a94
commit f5f02babdd
8 changed files with 131 additions and 30 deletions
+23
View File
@@ -932,6 +932,29 @@ TEST_F(LexerTest, TypeLiterals) {
EXPECT_EQ(buffer.GetTypeLiteralSize(*token_f1), 1);
}
TEST_F(LexerTest, TypeLiteralTooManyDigits) {
std::string code = "i";
code.append(10000, '9');
Testing::MockDiagnosticConsumer consumer;
EXPECT_CALL(
consumer,
HandleDiagnostic(AllOf(
DiagnosticAt(1, 2),
DiagnosticMessage(HasSubstr("Found a sequence of 10000 digits")))));
auto buffer = Lex(code, consumer);
EXPECT_TRUE(buffer.HasErrors());
ASSERT_THAT(buffer,
HasTokens(llvm::ArrayRef<ExpectedToken>{
{.kind = TokenKind::Error(),
.line = 1,
.column = 1,
.indent_column = 1,
.text = {code}},
{.kind = TokenKind::EndOfFile(), .line = 1, .column = 10002},
}));
}
TEST_F(LexerTest, DiagnosticTrailingComment) {
llvm::StringLiteral testcase = R"(
// Hello!