diff --git a/Ast/src/Parser.cpp b/Ast/src/Parser.cpp index 87af53cb1..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) + if (result.size() == 1 && (!FFlag::LuauDisallowVariadicInReturnParenType || !varargAnnotation)) { AstType* returnType = parseTypeSuffix(result[0], innerBegin); diff --git a/tests/Parser.test.cpp b/tests/Parser.test.cpp index 972d0edd7..d97d384dd 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."); } +TEST_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();