@@ -391,6 +391,7 @@ Parser::TypeASTResult Parser::parseType(Diag<> MessageID,
391
391
}
392
392
393
393
if (Tok.is (tok::arrow)) {
394
+ auto InputNode = SyntaxContext->popIf <ParsedTypeSyntax>().getValue ();
394
395
// Handle type-function if we have an arrow.
395
396
auto ArrowLoc = Tok.getLoc ();
396
397
auto Arrow = consumeTokenSyntax ();
@@ -403,23 +404,21 @@ Parser::TypeASTResult Parser::parseType(Diag<> MessageID,
403
404
}
404
405
ParserResult<TypeRepr> SecondHalf =
405
406
parseType (diag::expected_type_function_result);
407
+ auto SecondTy = SyntaxContext->popIf <ParsedTypeSyntax>();
406
408
if (SecondHalf.isParseError ()) {
409
+ SyntaxContext->addSyntax (InputNode);
407
410
if (Throws)
408
411
SyntaxContext->addSyntax (*Throws);
409
412
SyntaxContext->addSyntax (Arrow);
413
+ if (SecondTy)
414
+ SyntaxContext->addSyntax (*SecondTy);
410
415
if (SecondHalf.hasCodeCompletion ())
411
416
return makeParserCodeCompletionResult<TypeRepr>();
412
417
if (SecondHalf.isNull ())
413
418
return nullptr ;
414
419
}
415
420
416
421
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 ();
423
422
bool isVoid = false ;
424
423
if (auto TupleTypeNode = InputNode.getAs <ParsedTupleTypeSyntax>()) {
425
424
// Decompose TupleTypeSyntax and repack into FunctionType.
@@ -447,6 +446,13 @@ Parser::TypeASTResult Parser::parseType(Diag<> MessageID,
447
446
Builder.addArgumentsMember (ParsedSyntaxRecorder::makeTupleTypeElement (
448
447
InputNode, /* TrailingComma=*/ None, *SyntaxContext));
449
448
}
449
+
450
+ Builder.useReturnType (*SecondTy);
451
+ if (Throws)
452
+ Builder.useThrowsOrRethrowsKeyword (*Throws);
453
+ Builder.useArrow (Arrow);
454
+ Builder.useReturnType (*SecondTy);
455
+
450
456
SyntaxContext->addSyntax (Builder.build ());
451
457
452
458
auto FunctionType = SyntaxContext->topNode <FunctionTypeSyntax>();
@@ -1107,21 +1113,20 @@ Parser::TypeResult Parser::parseTypeTupleBody() {
1107
1113
// Parse the type annotation.
1108
1114
auto TypeLoc = Tok.getLoc ();
1109
1115
auto TypeASTResult = parseType (diag::expected_type);
1116
+ auto Type = SyntaxContext->popIf <ParsedTypeSyntax>();
1110
1117
if (TypeASTResult.hasCodeCompletion () || TypeASTResult.isNull ()) {
1111
1118
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 );
1114
1121
skipListUntilDeclRBraceSyntax (Junk, LParenLoc, tok::r_paren, tok::comma);
1115
1122
return TypeASTResult.hasCodeCompletion ()
1116
1123
? makeParserCodeCompletionStatus ()
1117
1124
: makeParserError ();
1118
1125
}
1119
1126
1120
- auto Type = *SyntaxContext->popIf <ParsedTypeSyntax>();
1121
-
1122
1127
if (IsInOutObsoleted) {
1123
1128
bool IsTypeAlreadyAttributed = false ;
1124
- if (auto AttributedType = Type. getAs <ParsedAttributedTypeSyntax>())
1129
+ if (auto AttributedType = Type-> getAs <ParsedAttributedTypeSyntax>())
1125
1130
IsTypeAlreadyAttributed = AttributedType->getDeferredSpecifier ().hasValue ();
1126
1131
1127
1132
if (IsTypeAlreadyAttributed) {
@@ -1167,7 +1172,7 @@ Parser::TypeResult Parser::parseTypeTupleBody() {
1167
1172
Comma = consumeTokenSyntaxIf (tok::comma);
1168
1173
1169
1174
auto Element = ParsedSyntaxRecorder::makeTupleTypeElement (
1170
- InOut, Name, SecondName, Colon, Type, ElementEllipsis, Initializer,
1175
+ InOut, Name, SecondName, Colon, * Type, ElementEllipsis, Initializer,
1171
1176
Comma, *SyntaxContext);
1172
1177
1173
1178
Junk.push_back (Element);
0 commit comments