Skip to content

Commit 0899eb6

Browse files
authored
Merge pull request swiftlang#26914 from rintaro/syntaxparse-genericargsyntax
[SyntaxParse] use parseGenericArgumentClauseSyntax()
2 parents b8f42d6 + 41eebd2 commit 0899eb6

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

lib/Parse/ParseType.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -669,19 +669,19 @@ Parser::TypeResult Parser::parseTypeIdentifier() {
669669
if (startsWithLess(Tok)) {
670670
SmallVector<TypeRepr *, 4> GenericArgsAST;
671671
SourceLoc LAngleLoc, RAngleLoc;
672-
auto GenericArgsResult =
673-
parseGenericArgumentsAST(GenericArgsAST, LAngleLoc, RAngleLoc);
672+
auto GenericArgsResult = parseGenericArgumentClauseSyntax();
674673
if (!GenericArgsResult.isSuccess()) {
675674
if (Base)
676675
Junk.push_back(*Base);
677676
if (Period)
678677
Junk.push_back(*Period);
679678
Junk.push_back(*Identifier);
680-
if (auto GenericJunk = SyntaxContext->popIf<ParsedSyntax>())
681-
Junk.push_back(*GenericJunk);
682-
return makeParsedResult<ParsedTypeSyntax>(Junk, GenericArgsResult);
679+
auto genericJunks = GenericArgsResult.getUnknownNodes();
680+
Junk.append(genericJunks.begin(), genericJunks.end());
681+
return makeParsedResult<ParsedTypeSyntax>(
682+
Junk, GenericArgsResult.getStatus());
683683
}
684-
GenericArgs = SyntaxContext->popIf<ParsedGenericArgumentClauseSyntax>();
684+
GenericArgs = GenericArgsResult.getResult();
685685
}
686686

687687
if (!Base)
@@ -1074,15 +1074,18 @@ Parser::TypeResult Parser::parseTypeTupleBody() {
10741074
// Consume a name.
10751075
NameLoc = Tok.getLoc();
10761076
Name = consumeArgumentLabelSyntax();
1077+
LocalJunk.push_back(*Name);
10771078

10781079
// If there is a second name, consume it as well.
10791080
if (Tok.canBeArgumentLabel()) {
10801081
SecondNameLoc = Tok.getLoc();
10811082
SecondName = consumeArgumentLabelSyntax();
1083+
LocalJunk.push_back(*SecondName);
10821084
}
10831085

10841086
// Consume the ':'.
10851087
if ((Colon = consumeTokenSyntaxIf(tok::colon))) {
1088+
LocalJunk.push_back(*Colon);
10861089
// If we succeed, then we successfully parsed a label.
10871090
if (Backtracking)
10881091
Backtracking->cancelBacktrack();
@@ -1091,8 +1094,6 @@ Parser::TypeResult Parser::parseTypeTupleBody() {
10911094
} else {
10921095
if (!Backtracking)
10931096
diagnose(Tok, diag::expected_parameter_colon);
1094-
Name = None;
1095-
SecondName = None;
10961097
NameLoc = SourceLoc();
10971098
SecondNameLoc = SourceLoc();
10981099
}
@@ -1103,20 +1104,14 @@ Parser::TypeResult Parser::parseTypeTupleBody() {
11031104

11041105
Backtracking.reset();
11051106

1106-
if (Name)
1107-
LocalJunk.push_back(*Name);
1108-
if (SecondName)
1109-
LocalJunk.push_back(*SecondName);
1110-
if (Colon)
1111-
LocalJunk.push_back(*Colon);
1112-
11131107
// Parse the type annotation.
11141108
auto TypeLoc = Tok.getLoc();
11151109
auto TypeASTResult = parseType(diag::expected_type);
11161110
if (TypeASTResult.hasCodeCompletion() || TypeASTResult.isNull()) {
1111+
Junk.append(LocalJunk.begin(), LocalJunk.end());
1112+
if (auto parsedT = SyntaxContext->popIf<ParsedTypeSyntax>())
1113+
Junk.push_back(*parsedT);
11171114
skipListUntilDeclRBraceSyntax(Junk, LParenLoc, tok::r_paren, tok::comma);
1118-
for (auto &&Item : LocalJunk)
1119-
Junk.push_back(Item);
11201115
return TypeASTResult.hasCodeCompletion()
11211116
? makeParserCodeCompletionStatus()
11221117
: makeParserError();

test/Syntax/round_trip_misc.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@ class C {
44
// Erroneous typealias decl.
55
typealias Inner: Foo = Int
66

7-
typealias Inner: Foo2 = [Generic<Int
7+
typealias Alias1 = [Generic<Int
8+
89

910
// Implict accessor with attribute at the top of its body.
1011
var x: Int {
1112
@objc
1213
func f() {}
1314
}
1415
}
16+
do {
17+
typealias Alias2 = () -> (a b: [Generic<Int
18+
}
19+
do {
20+
typealias Alias3 = (a b C,
21+
}
1522

1623
// Orphan '}' at top level
1724
}

0 commit comments

Comments
 (0)