mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Bespoke error for interpolated string fails
This commit is contained in:
parent
63654211c6
commit
efe3b7ca36
2 changed files with 14 additions and 4 deletions
|
@ -1574,6 +1574,12 @@ AstTypeOrPack Parser::parseSimpleTypeAnnotation(bool allowPack)
|
||||||
else
|
else
|
||||||
return {reportTypeAnnotationError(begin, {}, /*isMissing*/ false, "String literal contains malformed escape sequence")};
|
return {reportTypeAnnotationError(begin, {}, /*isMissing*/ false, "String literal contains malformed escape sequence")};
|
||||||
}
|
}
|
||||||
|
else if (lexer.current().type == Lexeme::InterpStringBegin || lexer.current().type == Lexeme::InterpStringEnd)
|
||||||
|
{
|
||||||
|
parseInterpString();
|
||||||
|
|
||||||
|
return {reportTypeAnnotationError(begin, {}, /*isMissing*/ false, "Interpolated string literals cannot be used as types")};
|
||||||
|
}
|
||||||
else if (lexer.current().type == Lexeme::BrokenString)
|
else if (lexer.current().type == Lexeme::BrokenString)
|
||||||
{
|
{
|
||||||
Location location = lexer.current().location;
|
Location location = lexer.current().location;
|
||||||
|
|
|
@ -1117,14 +1117,18 @@ TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_as_type_fail")
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
parse(R"(
|
parse(R"(
|
||||||
local a: `what` = `what`
|
local a: `what` = `???`
|
||||||
|
local b: `what {"the"}` = `???`
|
||||||
|
local c: `what {"the"} heck` = `???`
|
||||||
)");
|
)");
|
||||||
FAIL("Expected ParseErrors to be thrown");
|
FAIL("Expected ParseErrors to be thrown");
|
||||||
}
|
}
|
||||||
catch (const ParseErrors& e)
|
catch (const ParseErrors& parseErrors)
|
||||||
{
|
{
|
||||||
// CHECK_EQ("Interpolated strings cannot be used alone to call a function. Wrap this in parentheses.", e.getErrors().front().getMessage());
|
CHECK_EQ(parseErrors.getErrors().size(), 3);
|
||||||
CHECK_EQ("TODO", e.getErrors().front().getMessage());
|
|
||||||
|
for (ParseError error : parseErrors.getErrors())
|
||||||
|
CHECK_EQ(error.getMessage(), "Interpolated string literals cannot be used as types");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue