add fflag

This commit is contained in:
jackdotink 2024-06-04 16:27:49 -05:00
parent 9231c01f6d
commit 0f65b41459
2 changed files with 27 additions and 10 deletions

View file

@ -17,6 +17,7 @@ LUAU_FASTINTVARIABLE(LuauParseErrorLimit, 100)
// flag so that we don't break production games by reverting syntax changes. // flag so that we don't break production games by reverting syntax changes.
// See docs/SyntaxChanges.md for an explanation. // See docs/SyntaxChanges.md for an explanation.
LUAU_FASTFLAGVARIABLE(DebugLuauDeferredConstraintResolution, false) LUAU_FASTFLAGVARIABLE(DebugLuauDeferredConstraintResolution, false)
LUAU_FASTFLAGVARIABLE(LuauLeadingBarAndAmpersand, false)
namespace Luau namespace Luau
{ {
@ -1524,7 +1525,7 @@ AstType* Parser::parseTypeSuffix(AstType* type, const Location& begin)
{ {
TempVector<AstType*> parts(scratchType); TempVector<AstType*> parts(scratchType);
if (type != nullptr) if (!FFlag::LuauLeadingBarAndAmpersand || type != nullptr)
{ {
parts.push_back(type); parts.push_back(type);
} }
@ -1626,24 +1627,35 @@ AstTypeOrPack Parser::parseTypeOrPack()
AstType* Parser::parseType(bool inDeclarationContext) AstType* Parser::parseType(bool inDeclarationContext)
{ {
Location begin = lexer.current().location;
unsigned int oldRecursionCount = recursionCounter; unsigned int oldRecursionCount = recursionCounter;
// recursion counter is incremented in parseSimpleType and/or parseTypeSuffix // recursion counter is incremented in parseSimpleType and/or parseTypeSuffix
AstType* type = nullptr; Location begin = lexer.current().location;
Lexeme::Type c = lexer.current().type; if (FFlag::LuauLeadingBarAndAmpersand)
if (c != '|' && c != '&')
{ {
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; 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] `}' // Type ::= nil | Name[`.' Name] [ `<' Type [`,' ...] `>' ] | `typeof' `(' expr `)' | `{' [PropList] `}'

View file

@ -16,6 +16,7 @@ LUAU_FASTINT(LuauRecursionLimit);
LUAU_FASTINT(LuauTypeLengthLimit); LUAU_FASTINT(LuauTypeLengthLimit);
LUAU_FASTINT(LuauParseErrorLimit); LUAU_FASTINT(LuauParseErrorLimit);
LUAU_FASTFLAG(DebugLuauDeferredConstraintResolution); LUAU_FASTFLAG(DebugLuauDeferredConstraintResolution);
LUAU_FASTFLAG(LuauLeadingBarAndAmpersand);
namespace namespace
{ {
@ -3169,11 +3170,15 @@ TEST_CASE_FIXTURE(Fixture, "read_write_table_properties")
TEST_CASE_FIXTURE(Fixture, "can_parse_leading_bar_unions_successfully") TEST_CASE_FIXTURE(Fixture, "can_parse_leading_bar_unions_successfully")
{ {
ScopedFastFlag sff{FFlag::LuauLeadingBarAndAmpersand, true};
parse(R"(type A = | "Hello" | "World")"); parse(R"(type A = | "Hello" | "World")");
} }
TEST_CASE_FIXTURE(Fixture, "can_parse_leading_ampersand_intersections_successfully") TEST_CASE_FIXTURE(Fixture, "can_parse_leading_ampersand_intersections_successfully")
{ {
ScopedFastFlag sff{FFlag::LuauLeadingBarAndAmpersand, true};
parse(R"(type A = & { string } & { number })"); parse(R"(type A = & { string } & { number })");
} }