From 11787e83369c3ebf0ecbe24d0eb80f041163a4e9 Mon Sep 17 00:00:00 2001 From: Kampfkarren Date: Wed, 27 Jul 2022 02:25:12 -0700 Subject: [PATCH] Bespoke error for interpolated string after call --- Ast/src/Parser.cpp | 6 ++++++ tests/Parser.test.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Ast/src/Parser.cpp b/Ast/src/Parser.cpp index 9a9ac315..4f3d5299 100644 --- a/Ast/src/Parser.cpp +++ b/Ast/src/Parser.cpp @@ -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; diff --git a/tests/Parser.test.cpp b/tests/Parser.test.cpp index aec1fbe7..5c34ebcd 100644 --- a/tests/Parser.test.cpp +++ b/tests/Parser.test.cpp @@ -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