Allow interpolated strings without expressions, add TODO test for failing interp strings as types

This commit is contained in:
Kampfkarren 2022-07-27 22:12:27 -07:00
parent 92adca20bf
commit 63654211c6
4 changed files with 25 additions and 4 deletions

View file

@ -601,7 +601,7 @@ Lexeme Lexer::readInterpolatedStringBegin()
Position start = position(); Position start = position();
consume(); consume();
return readInterpolatedStringSection(start, Lexeme::InterpStringBegin, Lexeme::QuotedString); return readInterpolatedStringSection(start, Lexeme::InterpStringBegin, Lexeme::InterpStringEnd);
} }
Lexeme Lexer::readInterpolatedStringSection(Position start, Lexeme::Type formatType, Lexeme::Type endType) Lexeme Lexer::readInterpolatedStringSection(Position start, Lexeme::Type formatType, Lexeme::Type endType)

View file

@ -2203,7 +2203,7 @@ AstExpr* Parser::parseSimpleExpr()
} }
} }
} }
else if (lexer.current().type == Lexeme::RawString || lexer.current().type == Lexeme::QuotedString) else if (lexer.current().type == Lexeme::RawString || lexer.current().type == Lexeme::QuotedString || (FFlag::LuauInterpolatedStringBaseSupport && lexer.current().type == Lexeme::InterpStringEnd))
{ {
return parseString(); return parseString();
} }
@ -2603,11 +2603,11 @@ AstArray<AstTypeOrPack> Parser::parseTypeParams()
std::optional<AstArray<char>> Parser::parseCharArray() std::optional<AstArray<char>> Parser::parseCharArray()
{ {
LUAU_ASSERT(lexer.current().type == Lexeme::QuotedString || lexer.current().type == Lexeme::RawString); LUAU_ASSERT(lexer.current().type == Lexeme::QuotedString || lexer.current().type == Lexeme::RawString || lexer.current().type == Lexeme::InterpStringEnd);
scratchData.assign(lexer.current().data, lexer.current().length); scratchData.assign(lexer.current().data, lexer.current().length);
if (lexer.current().type == Lexeme::QuotedString) if (lexer.current().type == Lexeme::QuotedString || lexer.current().type == Lexeme::InterpStringEnd)
{ {
if (!Lexer::fixupQuotedString(scratchData)) if (!Lexer::fixupQuotedString(scratchData))
{ {

View file

@ -1110,6 +1110,24 @@ TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_after_prefixexp")
} }
} }
TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_as_type_fail")
{
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
try
{
parse(R"(
local a: `what` = `what`
)");
FAIL("Expected ParseErrors to be thrown");
}
catch (const ParseErrors& e)
{
// CHECK_EQ("Interpolated strings cannot be used alone to call a function. Wrap this in parentheses.", e.getErrors().front().getMessage());
CHECK_EQ("TODO", e.getErrors().front().getMessage());
}
}
TEST_CASE_FIXTURE(Fixture, "parse_nesting_based_end_detection") TEST_CASE_FIXTURE(Fixture, "parse_nesting_based_end_detection")
{ {
try try

View file

@ -31,7 +31,10 @@ assertEq(`This {localName} does not exist`, "This nil does not exist")
assertEq(`Welcome to \ assertEq(`Welcome to \
{name}!`, "Welcome to \nLuau!") {name}!`, "Welcome to \nLuau!")
assertEq(`empty`, "empty")
assertEq(`Escaped brace: \{}`, "Escaped brace: {}") assertEq(`Escaped brace: \{}`, "Escaped brace: {}")
assertEq(`Escaped brace \{} with {"expression"}`, "Escaped brace {} with expression")
assertEq(`Backslash \ that escapes the space is not a part of the string...`, "Backslash that escapes the space is not a part of the string...") assertEq(`Backslash \ that escapes the space is not a part of the string...`, "Backslash that escapes the space is not a part of the string...")
assertEq(`Escaped backslash \\`, "Escaped backslash \\") assertEq(`Escaped backslash \\`, "Escaped backslash \\")
assertEq(`Escaped backtick: \``, "Escaped backtick: `") assertEq(`Escaped backtick: \``, "Escaped backtick: `")