Skip to content

[SyntaxParse] use parseGenericArgumentClauseSyntax() #26914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions lib/Parse/ParseType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,19 +669,19 @@ Parser::TypeResult Parser::parseTypeIdentifier() {
if (startsWithLess(Tok)) {
SmallVector<TypeRepr *, 4> GenericArgsAST;
SourceLoc LAngleLoc, RAngleLoc;
auto GenericArgsResult =
parseGenericArgumentsAST(GenericArgsAST, LAngleLoc, RAngleLoc);
auto GenericArgsResult = parseGenericArgumentClauseSyntax();
if (!GenericArgsResult.isSuccess()) {
if (Base)
Junk.push_back(*Base);
if (Period)
Junk.push_back(*Period);
Junk.push_back(*Identifier);
if (auto GenericJunk = SyntaxContext->popIf<ParsedSyntax>())
Junk.push_back(*GenericJunk);
return makeParsedResult<ParsedTypeSyntax>(Junk, GenericArgsResult);
auto genericJunks = GenericArgsResult.getUnknownNodes();
Junk.append(genericJunks.begin(), genericJunks.end());
return makeParsedResult<ParsedTypeSyntax>(
Junk, GenericArgsResult.getStatus());
}
GenericArgs = SyntaxContext->popIf<ParsedGenericArgumentClauseSyntax>();
GenericArgs = GenericArgsResult.getResult();
}

if (!Base)
Expand Down Expand Up @@ -1074,15 +1074,18 @@ Parser::TypeResult Parser::parseTypeTupleBody() {
// Consume a name.
NameLoc = Tok.getLoc();
Name = consumeArgumentLabelSyntax();
LocalJunk.push_back(*Name);

// If there is a second name, consume it as well.
if (Tok.canBeArgumentLabel()) {
SecondNameLoc = Tok.getLoc();
SecondName = consumeArgumentLabelSyntax();
LocalJunk.push_back(*SecondName);
}

// Consume the ':'.
if ((Colon = consumeTokenSyntaxIf(tok::colon))) {
LocalJunk.push_back(*Colon);
// If we succeed, then we successfully parsed a label.
if (Backtracking)
Backtracking->cancelBacktrack();
Expand All @@ -1091,8 +1094,6 @@ Parser::TypeResult Parser::parseTypeTupleBody() {
} else {
if (!Backtracking)
diagnose(Tok, diag::expected_parameter_colon);
Name = None;
SecondName = None;
NameLoc = SourceLoc();
SecondNameLoc = SourceLoc();
}
Expand All @@ -1103,20 +1104,14 @@ Parser::TypeResult Parser::parseTypeTupleBody() {

Backtracking.reset();

if (Name)
LocalJunk.push_back(*Name);
if (SecondName)
LocalJunk.push_back(*SecondName);
if (Colon)
LocalJunk.push_back(*Colon);

// Parse the type annotation.
auto TypeLoc = Tok.getLoc();
auto TypeASTResult = parseType(diag::expected_type);
if (TypeASTResult.hasCodeCompletion() || TypeASTResult.isNull()) {
Junk.append(LocalJunk.begin(), LocalJunk.end());
if (auto parsedT = SyntaxContext->popIf<ParsedTypeSyntax>())
Junk.push_back(*parsedT);
skipListUntilDeclRBraceSyntax(Junk, LParenLoc, tok::r_paren, tok::comma);
for (auto &&Item : LocalJunk)
Junk.push_back(Item);
return TypeASTResult.hasCodeCompletion()
? makeParserCodeCompletionStatus()
: makeParserError();
Expand Down
9 changes: 8 additions & 1 deletion test/Syntax/round_trip_misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ class C {
// Erroneous typealias decl.
typealias Inner: Foo = Int

typealias Inner: Foo2 = [Generic<Int
typealias Alias1 = [Generic<Int


// Implict accessor with attribute at the top of its body.
var x: Int {
@objc
func f() {}
}
}
do {
typealias Alias2 = () -> (a b: [Generic<Int
}
do {
typealias Alias3 = (a b C,
}

// Orphan '}' at top level
}
Expand Down