Bespoke error for interpolated string after call

This commit is contained in:
Kampfkarren 2022-07-27 02:25:12 -07:00
parent 591192c3e5
commit 11787e8336
2 changed files with 31 additions and 0 deletions

View file

@ -2008,6 +2008,12 @@ AstExpr* Parser::parsePrimaryExpr(bool asStatement)
{
expr = parseFunctionArgs(expr, false, Location());
}
else if (lexer.current().type == Lexeme::InterpStringBegin)
{
report(lexer.current().location, "Interpolated strings cannot be used alone to call a function. Wrap this in parentheses.");
break;
}
else
{
break;

View file

@ -1036,6 +1036,8 @@ TEST_CASE_FIXTURE(Fixture, "parse_compound_assignment_error_multiple")
TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_double_brace_begin")
{
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
try
{
parse(R"(
@ -1051,6 +1053,8 @@ TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_double_brace_begin")
TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_double_brace_mid")
{
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
try
{
parse(R"(
@ -1066,6 +1070,8 @@ TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_double_brace_mid")
TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_without_format")
{
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
try
{
parse(R"(
@ -1081,6 +1087,8 @@ TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_without_format")
TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_without_end_brace")
{
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
auto columnOfEndBraceError = [=](const char* code)
{
try
@ -1102,6 +1110,23 @@ TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_without_end_brace")
CHECK_NE(columnOfEndBraceError("_ = `{a`"), columnOfEndBraceError("_ = `{a`"));
}
TEST_CASE_FIXTURE(Fixture, "parse_interpolated_string_after_prefixexp")
{
ScopedFastFlag sff{"LuauInterpolatedStringBaseSupport", true};
try
{
parse(R"(
print`Hello {name}`
)");
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());
}
}
TEST_CASE_FIXTURE(Fixture, "parse_nesting_based_end_detection")
{
try