Make interpolated string with no formatting a syntax error

This commit is contained in:
Kampfkarren 2022-07-26 19:39:54 -07:00
parent f8be1070c3
commit 8d0d271cd3
4 changed files with 22 additions and 1 deletions

View file

@ -86,6 +86,7 @@ struct Lexeme
BrokenUnicode, BrokenUnicode,
BrokenInterpDoubleBrace, BrokenInterpDoubleBrace,
BrokenInterpNoFormat,
Error, Error,

View file

@ -187,6 +187,9 @@ std::string Lexeme::toString() const
case BrokenInterpDoubleBrace: case BrokenInterpDoubleBrace:
return "'{{', which is invalid (did you mean '\\{'?)"; return "'{{', which is invalid (did you mean '\\{'?)";
case BrokenInterpNoFormat:
return "interpolated string with no formatting";
case BrokenUnicode: case BrokenUnicode:
if (codepoint) if (codepoint)
{ {
@ -631,7 +634,7 @@ Lexeme Lexer::readInterpolatedStringBegin()
if (!readSectionOpt) if (!readSectionOpt)
{ {
LUAU_ASSERT(!"INTERP TODO: Error if there was no interpolated expression"); return Lexeme(Location(start, position()), Lexeme::BrokenInterpNoFormat);
} }
return *readSectionOpt; return *readSectionOpt;

View file

@ -2683,6 +2683,8 @@ AstExpr* Parser::parseInterpString()
return reportExprError(location, {}, "Malformed interpolated string"); return reportExprError(location, {}, "Malformed interpolated string");
case Lexeme::BrokenInterpDoubleBrace: case Lexeme::BrokenInterpDoubleBrace:
return reportExprError(location, {}, "Double braces are not permitted within interpolated strings. Did you mean '\\{'?"); return reportExprError(location, {}, "Double braces are not permitted within interpolated strings. Did you mean '\\{'?");
default:
break;
} }
} while (true); } while (true);
} }

View file

@ -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") TEST_CASE_FIXTURE(Fixture, "parse_nesting_based_end_detection")
{ {
try try