From 0f65b41459235d52b3bff8a6f0c99669423f32b6 Mon Sep 17 00:00:00 2001 From: jackdotink Date: Tue, 4 Jun 2024 16:27:49 -0500 Subject: [PATCH] add fflag --- Ast/src/Parser.cpp | 32 ++++++++++++++++++++++---------- tests/Parser.test.cpp | 5 +++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Ast/src/Parser.cpp b/Ast/src/Parser.cpp index ce4ffa71..5ca480e8 100644 --- a/Ast/src/Parser.cpp +++ b/Ast/src/Parser.cpp @@ -17,6 +17,7 @@ LUAU_FASTINTVARIABLE(LuauParseErrorLimit, 100) // flag so that we don't break production games by reverting syntax changes. // See docs/SyntaxChanges.md for an explanation. LUAU_FASTFLAGVARIABLE(DebugLuauDeferredConstraintResolution, false) +LUAU_FASTFLAGVARIABLE(LuauLeadingBarAndAmpersand, false) namespace Luau { @@ -1524,7 +1525,7 @@ AstType* Parser::parseTypeSuffix(AstType* type, const Location& begin) { TempVector parts(scratchType); - if (type != nullptr) + if (!FFlag::LuauLeadingBarAndAmpersand || type != nullptr) { parts.push_back(type); } @@ -1626,24 +1627,35 @@ AstTypeOrPack Parser::parseTypeOrPack() AstType* Parser::parseType(bool inDeclarationContext) { - Location begin = lexer.current().location; - unsigned int oldRecursionCount = recursionCounter; // recursion counter is incremented in parseSimpleType and/or parseTypeSuffix - AstType* type = nullptr; + Location begin = lexer.current().location; - Lexeme::Type c = lexer.current().type; - if (c != '|' && c != '&') + if (FFlag::LuauLeadingBarAndAmpersand) { - type = parseSimpleType(/* allowPack= */ false, /* in declaration context */ inDeclarationContext).type; + AstType* type = nullptr; + + Lexeme::Type c = lexer.current().type; + if (c != '|' && c != '&') + { + type = parseSimpleType(/* allowPack= */ false, /* in declaration context */ inDeclarationContext).type; + recursionCounter = oldRecursionCount; + } + + AstType* typeWithSuffix = parseTypeSuffix(type, begin); recursionCounter = oldRecursionCount; + + return typeWithSuffix; } + else + { + AstType* type = parseSimpleType(/* allowPack= */ false, /* in declaration context */ inDeclarationContext).type; - AstType* typeWithSuffix = parseTypeSuffix(type, begin); - recursionCounter = oldRecursionCount; + recursionCounter = oldRecursionCount; - return typeWithSuffix; + return parseTypeSuffix(type, begin); + } } // Type ::= nil | Name[`.' Name] [ `<' Type [`,' ...] `>' ] | `typeof' `(' expr `)' | `{' [PropList] `}' diff --git a/tests/Parser.test.cpp b/tests/Parser.test.cpp index d5d22faa..d5c673e0 100644 --- a/tests/Parser.test.cpp +++ b/tests/Parser.test.cpp @@ -16,6 +16,7 @@ LUAU_FASTINT(LuauRecursionLimit); LUAU_FASTINT(LuauTypeLengthLimit); LUAU_FASTINT(LuauParseErrorLimit); LUAU_FASTFLAG(DebugLuauDeferredConstraintResolution); +LUAU_FASTFLAG(LuauLeadingBarAndAmpersand); namespace { @@ -3169,11 +3170,15 @@ TEST_CASE_FIXTURE(Fixture, "read_write_table_properties") TEST_CASE_FIXTURE(Fixture, "can_parse_leading_bar_unions_successfully") { + ScopedFastFlag sff{FFlag::LuauLeadingBarAndAmpersand, true}; + parse(R"(type A = | "Hello" | "World")"); } TEST_CASE_FIXTURE(Fixture, "can_parse_leading_ampersand_intersections_successfully") { + ScopedFastFlag sff{FFlag::LuauLeadingBarAndAmpersand, true}; + parse(R"(type A = & { string } & { number })"); }