From eae5989abbeba3b68ff87298c37011918dc0fe86 Mon Sep 17 00:00:00 2001 From: Jack <85714123+jackdotink@users.noreply.github.com> Date: Wed, 10 Jul 2024 19:07:29 -0500 Subject: [PATCH 1/4] Update Parser.cpp --- Ast/src/Parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ast/src/Parser.cpp b/Ast/src/Parser.cpp index 87af53cb1..b09e93831 100644 --- a/Ast/src/Parser.cpp +++ b/Ast/src/Parser.cpp @@ -1463,7 +1463,7 @@ std::pair Parser::parseReturnType() if (lexer.current().type != Lexeme::SkinnyArrow && resultNames.empty()) { // If it turns out that it's just '(A)', it's possible that there are unions/intersections to follow, so fold over it. - if (result.size() == 1) + if (result.size() == 1 && !varargAnnotation) { AstType* returnType = parseTypeSuffix(result[0], innerBegin); From fc610b9999c4aeab4c40e5d3fbf768ebbcfdda8a Mon Sep 17 00:00:00 2001 From: Jack <85714123+jackdotink@users.noreply.github.com> Date: Wed, 10 Jul 2024 19:12:56 -0500 Subject: [PATCH 2/4] put behind flag --- Ast/src/Parser.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Ast/src/Parser.cpp b/Ast/src/Parser.cpp index b09e93831..54d92fd85 100644 --- a/Ast/src/Parser.cpp +++ b/Ast/src/Parser.cpp @@ -22,6 +22,7 @@ LUAU_FASTFLAGVARIABLE(LuauLeadingBarAndAmpersand2, false) LUAU_FASTFLAGVARIABLE(LuauNativeAttribute, false) LUAU_FASTFLAGVARIABLE(LuauAttributeSyntaxFunExpr, false) LUAU_FASTFLAGVARIABLE(LuauDeclarationExtraPropData, false) +LUAU_FASTFLAGVARIABLE(LuauDisallowVariadicInReturnParenType, false) namespace Luau { @@ -1463,7 +1464,7 @@ std::pair Parser::parseReturnType() if (lexer.current().type != Lexeme::SkinnyArrow && resultNames.empty()) { // If it turns out that it's just '(A)', it's possible that there are unions/intersections to follow, so fold over it. - if (result.size() == 1 && !varargAnnotation) + if (result.size() == 1 && (!FFlag::LuauDisallowVariadicInReturnParenType || !varargAnnotation)) { AstType* returnType = parseTypeSuffix(result[0], innerBegin); From 865ea44a1f18ca88c0f9d93cfacd3178470a41ae Mon Sep 17 00:00:00 2001 From: jackdotink Date: Mon, 15 Jul 2024 15:21:43 -0500 Subject: [PATCH 3/4] add test --- tests/Parser.test.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Parser.test.cpp b/tests/Parser.test.cpp index 972d0edd7..129892306 100644 --- a/tests/Parser.test.cpp +++ b/tests/Parser.test.cpp @@ -20,6 +20,7 @@ LUAU_FASTFLAG(LuauAttributeSyntax); LUAU_FASTFLAG(LuauLeadingBarAndAmpersand2); LUAU_FASTFLAG(LuauAttributeSyntaxFunExpr); LUAU_FASTFLAG(LuauDeclarationExtraPropData); +LUAU_FASTFLAG(LuauDisallowVariadicInReturnParenType); namespace { @@ -3565,5 +3566,11 @@ TEST_CASE_FIXTURE(Fixture, "mixed_leading_intersection_and_union_not_allowed") matchParseError("type A = | number & string & boolean", "Mixing union and intersection types is not allowed; consider wrapping in parentheses."); } +TEXT_CASE_FIXTURE(Fixture, "do_not_parse_variadic_type_in_paren_type_in_returns") +{ + ScopedFastFlag sff{FFlag::LuauDisallowVariadicInReturnParenType, true}; + + matchParseError("local function f(): (number, ...string) | boolean end", "Expected identifier when parsing expression, got '|'"); +} TEST_SUITE_END(); From 32ec9ba0ca78b22b047c448b3fb805a81ec18c48 Mon Sep 17 00:00:00 2001 From: jackdotink Date: Mon, 15 Jul 2024 15:26:32 -0500 Subject: [PATCH 4/4] fix stupid error --- tests/Parser.test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Parser.test.cpp b/tests/Parser.test.cpp index 129892306..d97d384dd 100644 --- a/tests/Parser.test.cpp +++ b/tests/Parser.test.cpp @@ -3566,7 +3566,7 @@ TEST_CASE_FIXTURE(Fixture, "mixed_leading_intersection_and_union_not_allowed") matchParseError("type A = | number & string & boolean", "Mixing union and intersection types is not allowed; consider wrapping in parentheses."); } -TEXT_CASE_FIXTURE(Fixture, "do_not_parse_variadic_type_in_paren_type_in_returns") +TEST_CASE_FIXTURE(Fixture, "do_not_parse_variadic_type_in_paren_type_in_returns") { ScopedFastFlag sff{FFlag::LuauDisallowVariadicInReturnParenType, true};