Skip to content

Commit 638e0e1

Browse files
---
yaml --- r: 343230 b: refs/heads/master-rebranch c: f1f75ca h: refs/heads/master
1 parent 39e2fef commit 638e0e1

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14551455
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14561456
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14571457
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1458-
refs/heads/master-rebranch: 684213415224f8367c35734e8996d26d01e3202a
1458+
refs/heads/master-rebranch: f1f75ca9f4ba0fad978f5944f02a3e3b1af69f35
14591459
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14601460
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14611461
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec

branches/master-rebranch/lib/Parse/ParseType.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ Parser::TypeASTResult Parser::parseType(Diag<> MessageID,
391391
}
392392

393393
if (Tok.is(tok::arrow)) {
394+
auto InputNode = SyntaxContext->popIf<ParsedTypeSyntax>().getValue();
394395
// Handle type-function if we have an arrow.
395396
auto ArrowLoc = Tok.getLoc();
396397
auto Arrow = consumeTokenSyntax();
@@ -403,23 +404,21 @@ Parser::TypeASTResult Parser::parseType(Diag<> MessageID,
403404
}
404405
ParserResult<TypeRepr> SecondHalf =
405406
parseType(diag::expected_type_function_result);
407+
auto SecondTy = SyntaxContext->popIf<ParsedTypeSyntax>();
406408
if (SecondHalf.isParseError()) {
409+
SyntaxContext->addSyntax(InputNode);
407410
if (Throws)
408411
SyntaxContext->addSyntax(*Throws);
409412
SyntaxContext->addSyntax(Arrow);
413+
if (SecondTy)
414+
SyntaxContext->addSyntax(*SecondTy);
410415
if (SecondHalf.hasCodeCompletion())
411416
return makeParserCodeCompletionResult<TypeRepr>();
412417
if (SecondHalf.isNull())
413418
return nullptr;
414419
}
415420

416421
ParsedFunctionTypeSyntaxBuilder Builder(*SyntaxContext);
417-
Builder.useReturnType(SyntaxContext->popIf<ParsedTypeSyntax>().getValue());
418-
Builder.useArrow(Arrow);
419-
if (Throws)
420-
Builder.useThrowsOrRethrowsKeyword(*Throws);
421-
422-
auto InputNode = SyntaxContext->popIf<ParsedTypeSyntax>().getValue();
423422
bool isVoid = false;
424423
if (auto TupleTypeNode = InputNode.getAs<ParsedTupleTypeSyntax>()) {
425424
// Decompose TupleTypeSyntax and repack into FunctionType.
@@ -447,6 +446,13 @@ Parser::TypeASTResult Parser::parseType(Diag<> MessageID,
447446
Builder.addArgumentsMember(ParsedSyntaxRecorder::makeTupleTypeElement(
448447
InputNode, /*TrailingComma=*/None, *SyntaxContext));
449448
}
449+
450+
Builder.useReturnType(*SecondTy);
451+
if (Throws)
452+
Builder.useThrowsOrRethrowsKeyword(*Throws);
453+
Builder.useArrow(Arrow);
454+
Builder.useReturnType(*SecondTy);
455+
450456
SyntaxContext->addSyntax(Builder.build());
451457

452458
auto FunctionType = SyntaxContext->topNode<FunctionTypeSyntax>();
@@ -1107,21 +1113,20 @@ Parser::TypeResult Parser::parseTypeTupleBody() {
11071113
// Parse the type annotation.
11081114
auto TypeLoc = Tok.getLoc();
11091115
auto TypeASTResult = parseType(diag::expected_type);
1116+
auto Type = SyntaxContext->popIf<ParsedTypeSyntax>();
11101117
if (TypeASTResult.hasCodeCompletion() || TypeASTResult.isNull()) {
11111118
Junk.append(LocalJunk.begin(), LocalJunk.end());
1112-
if (auto parsedT = SyntaxContext->popIf<ParsedTypeSyntax>())
1113-
Junk.push_back(*parsedT);
1119+
if (Type)
1120+
Junk.push_back(*Type);
11141121
skipListUntilDeclRBraceSyntax(Junk, LParenLoc, tok::r_paren, tok::comma);
11151122
return TypeASTResult.hasCodeCompletion()
11161123
? makeParserCodeCompletionStatus()
11171124
: makeParserError();
11181125
}
11191126

1120-
auto Type = *SyntaxContext->popIf<ParsedTypeSyntax>();
1121-
11221127
if (IsInOutObsoleted) {
11231128
bool IsTypeAlreadyAttributed = false;
1124-
if (auto AttributedType = Type.getAs<ParsedAttributedTypeSyntax>())
1129+
if (auto AttributedType = Type->getAs<ParsedAttributedTypeSyntax>())
11251130
IsTypeAlreadyAttributed = AttributedType->getDeferredSpecifier().hasValue();
11261131

11271132
if (IsTypeAlreadyAttributed) {
@@ -1167,7 +1172,7 @@ Parser::TypeResult Parser::parseTypeTupleBody() {
11671172
Comma = consumeTokenSyntaxIf(tok::comma);
11681173

11691174
auto Element = ParsedSyntaxRecorder::makeTupleTypeElement(
1170-
InOut, Name, SecondName, Colon, Type, ElementEllipsis, Initializer,
1175+
InOut, Name, SecondName, Colon, *Type, ElementEllipsis, Initializer,
11711176
Comma, *SyntaxContext);
11721177

11731178
Junk.push_back(Element);

branches/master-rebranch/test/Frontend/dump-parse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not %target-swift-frontend -dump-parse %s 2>&1 | %FileCheck %s
1+
// RUN: not %target-swift-frontend -dump-parse %s | %FileCheck %s
22
// RUN: not %target-swift-frontend -dump-ast %s | %FileCheck %s -check-prefix=CHECK-AST
33

44
// CHECK-LABEL: (func_decl{{.*}}"foo(_:)"

branches/master-rebranch/test/Syntax/round_trip_misc.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ do {
1919
do {
2020
typealias Alias3 = (a b C,
2121
}
22+
do {
23+
typealias Alias3 = () -> @objc func
24+
}
2225

2326
// Orphan '}' at top level
2427
}

0 commit comments

Comments
 (0)