@@ -423,6 +423,9 @@ TypeRepr *ASTGen::generate(ImplicitlyUnwrappedOptionalTypeSyntax Type,
423
423
TypeRepr *ASTGen::generate (UnknownTypeSyntax Type, SourceLoc &Loc) {
424
424
auto ChildrenCount = Type.getNumChildren ();
425
425
426
+ // Recover from C-style array type:
427
+ // type '[' ']'
428
+ // type '[' expr ']'
426
429
if (ChildrenCount == 3 || ChildrenCount == 4 ) {
427
430
auto Element = Type.getChild (0 )->getAs <TypeSyntax>();
428
431
auto LSquare = Type.getChild (1 )->getAs <TokenSyntax>();
@@ -436,6 +439,8 @@ TypeRepr *ASTGen::generate(UnknownTypeSyntax Type, SourceLoc &Loc) {
436
439
}
437
440
}
438
441
442
+ // Recover from extra `[`:
443
+ // type `[`
439
444
if (ChildrenCount == 2 ) {
440
445
auto Element = Type.getChild (0 )->getAs <TypeSyntax>();
441
446
auto LSquare = Type.getChild (1 )->getAs <TokenSyntax>();
@@ -445,6 +450,8 @@ TypeRepr *ASTGen::generate(UnknownTypeSyntax Type, SourceLoc &Loc) {
445
450
}
446
451
}
447
452
453
+ // Recover from old-style protocol composition:
454
+ // `protocol` `<` protocols `>`
448
455
if (ChildrenCount >= 2 ) {
449
456
auto Protocol = Type.getChild (0 )->getAs <TokenSyntax>();
450
457
@@ -472,6 +479,7 @@ TypeRepr *ASTGen::generate(UnknownTypeSyntax Type, SourceLoc &Loc) {
472
479
}
473
480
}
474
481
482
+ // Create ErrorTypeRepr for keywords.
475
483
if (ChildrenCount == 1 ) {
476
484
auto Keyword = Type.getChild (0 )->getAs <TokenSyntax>();
477
485
if (Keyword && isTokenKeyword (Keyword->getTokenKind ())) {
@@ -480,6 +488,7 @@ TypeRepr *ASTGen::generate(UnknownTypeSyntax Type, SourceLoc &Loc) {
480
488
}
481
489
}
482
490
491
+ // Create empty TupleTypeRepr for types starting with `(`.
483
492
if (ChildrenCount >= 1 ) {
484
493
auto LParen = Type.getChild (0 )->getAs <TokenSyntax>();
485
494
if (LParen && LParen->getTokenKind () == tok::l_paren) {
0 commit comments