Bespoke error for interpolated string fails

This commit is contained in:
Kampfkarren 2022-07-27 22:42:37 -07:00
parent 63654211c6
commit efe3b7ca36
2 changed files with 14 additions and 4 deletions

View file

@ -1574,6 +1574,12 @@ AstTypeOrPack Parser::parseSimpleTypeAnnotation(bool allowPack)
else
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)
{
Location location = lexer.current().location;

View file

@ -1117,14 +1117,18 @@ TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_as_type_fail")
try
{
parse(R"(
local a: `what` = `what`
local a: `what` = `???`
local b: `what {"the"}` = `???`
local c: `what {"the"} heck` = `???`
)");
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("TODO", e.getErrors().front().getMessage());
CHECK_EQ(parseErrors.getErrors().size(), 3);
for (ParseError error : parseErrors.getErrors())
CHECK_EQ(error.getMessage(), "Interpolated string literals cannot be used as types");
}
}