mirror of
https://github.com/luau-lang/luau.git
synced 2025-04-10 22:00:54 +01:00
implement leading bar and ampersand in types
This commit is contained in:
parent
daf79328fc
commit
4f05a860cb
2 changed files with 23 additions and 3 deletions
|
@ -1523,7 +1523,11 @@ AstType* Parser::parseFunctionTypeTail(const Lexeme& begin, AstArray<AstGenericT
|
||||||
AstType* Parser::parseTypeSuffix(AstType* type, const Location& begin)
|
AstType* Parser::parseTypeSuffix(AstType* type, const Location& begin)
|
||||||
{
|
{
|
||||||
TempVector<AstType*> parts(scratchType);
|
TempVector<AstType*> parts(scratchType);
|
||||||
parts.push_back(type);
|
|
||||||
|
if (type != nullptr)
|
||||||
|
{
|
||||||
|
parts.push_back(type);
|
||||||
|
}
|
||||||
|
|
||||||
incrementRecursionCounter("type annotation");
|
incrementRecursionCounter("type annotation");
|
||||||
|
|
||||||
|
@ -1622,11 +1626,17 @@ AstTypeOrPack Parser::parseTypeOrPack()
|
||||||
|
|
||||||
AstType* Parser::parseType(bool inDeclarationContext)
|
AstType* Parser::parseType(bool inDeclarationContext)
|
||||||
{
|
{
|
||||||
|
Location begin = lexer.current().location;
|
||||||
|
|
||||||
|
Lexeme::Type c = lexer.current().type;
|
||||||
|
if (c == '|' || c == '&')
|
||||||
|
{
|
||||||
|
return parseTypeSuffix(nullptr, begin);
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int oldRecursionCount = recursionCounter;
|
unsigned int oldRecursionCount = recursionCounter;
|
||||||
// recursion counter is incremented in parseSimpleType
|
// recursion counter is incremented in parseSimpleType
|
||||||
|
|
||||||
Location begin = lexer.current().location;
|
|
||||||
|
|
||||||
AstType* type = parseSimpleType(/* allowPack= */ false, /* in declaration context */ inDeclarationContext).type;
|
AstType* type = parseSimpleType(/* allowPack= */ false, /* in declaration context */ inDeclarationContext).type;
|
||||||
|
|
||||||
recursionCounter = oldRecursionCount;
|
recursionCounter = oldRecursionCount;
|
||||||
|
|
|
@ -3167,4 +3167,14 @@ TEST_CASE_FIXTURE(Fixture, "read_write_table_properties")
|
||||||
LUAU_ASSERT(pr.errors.size() == 0);
|
LUAU_ASSERT(pr.errors.size() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE_FIXTURE(Fixture, "can_parse_leading_bar_unions_successfully")
|
||||||
|
{
|
||||||
|
parse(R"(type A = | "Hello" | "World")");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE_FIXTURE(Fixture, "can_parse_leading_ampersand_intersections_successfully")
|
||||||
|
{
|
||||||
|
parse(R"(type A = & { string } & { number })");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_SUITE_END();
|
TEST_SUITE_END();
|
||||||
|
|
Loading…
Add table
Reference in a new issue