mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Make interpolated string with no formatting a syntax error
This commit is contained in:
parent
f8be1070c3
commit
8d0d271cd3
4 changed files with 22 additions and 1 deletions
|
@ -86,6 +86,7 @@ struct Lexeme
|
|||
BrokenUnicode,
|
||||
|
||||
BrokenInterpDoubleBrace,
|
||||
BrokenInterpNoFormat,
|
||||
|
||||
Error,
|
||||
|
||||
|
|
|
@ -187,6 +187,9 @@ std::string Lexeme::toString() const
|
|||
case BrokenInterpDoubleBrace:
|
||||
return "'{{', which is invalid (did you mean '\\{'?)";
|
||||
|
||||
case BrokenInterpNoFormat:
|
||||
return "interpolated string with no formatting";
|
||||
|
||||
case BrokenUnicode:
|
||||
if (codepoint)
|
||||
{
|
||||
|
@ -631,7 +634,7 @@ Lexeme Lexer::readInterpolatedStringBegin()
|
|||
|
||||
if (!readSectionOpt)
|
||||
{
|
||||
LUAU_ASSERT(!"INTERP TODO: Error if there was no interpolated expression");
|
||||
return Lexeme(Location(start, position()), Lexeme::BrokenInterpNoFormat);
|
||||
}
|
||||
|
||||
return *readSectionOpt;
|
||||
|
|
|
@ -2683,6 +2683,8 @@ AstExpr* Parser::parseInterpString()
|
|||
return reportExprError(location, {}, "Malformed interpolated string");
|
||||
case Lexeme::BrokenInterpDoubleBrace:
|
||||
return reportExprError(location, {}, "Double braces are not permitted within interpolated strings. Did you mean '\\{'?");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
|
|
@ -1065,6 +1065,21 @@ TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_double_brace_mid")
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_without_format")
|
||||
{
|
||||
try
|
||||
{
|
||||
parse(R"(
|
||||
_ = `doge`
|
||||
)");
|
||||
FAIL("Expected ParseErrors to be thrown");
|
||||
}
|
||||
catch (const ParseErrors& e)
|
||||
{
|
||||
CHECK_EQ("Expected identifier when parsing expression, got interpolated string with no formatting", e.getErrors().front().getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(Fixture, "parse_nesting_based_end_detection")
|
||||
{
|
||||
try
|
||||
|
|
Loading…
Add table
Reference in a new issue