Skip to content

Commit 02a323e

Browse files
author
Jan Svoboda
committed
Add comments to ASTGen's UnknownTypeSyntax recovery
1 parent be0ba7d commit 02a323e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/Parse/ASTGen.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ TypeRepr *ASTGen::generate(ImplicitlyUnwrappedOptionalTypeSyntax Type,
423423
TypeRepr *ASTGen::generate(UnknownTypeSyntax Type, SourceLoc &Loc) {
424424
auto ChildrenCount = Type.getNumChildren();
425425

426+
// Recover from C-style array type:
427+
// type '[' ']'
428+
// type '[' expr ']'
426429
if (ChildrenCount == 3 || ChildrenCount == 4) {
427430
auto Element = Type.getChild(0)->getAs<TypeSyntax>();
428431
auto LSquare = Type.getChild(1)->getAs<TokenSyntax>();
@@ -436,6 +439,8 @@ TypeRepr *ASTGen::generate(UnknownTypeSyntax Type, SourceLoc &Loc) {
436439
}
437440
}
438441

442+
// Recover from extra `[`:
443+
// type `[`
439444
if (ChildrenCount == 2) {
440445
auto Element = Type.getChild(0)->getAs<TypeSyntax>();
441446
auto LSquare = Type.getChild(1)->getAs<TokenSyntax>();
@@ -445,6 +450,8 @@ TypeRepr *ASTGen::generate(UnknownTypeSyntax Type, SourceLoc &Loc) {
445450
}
446451
}
447452

453+
// Recover from old-style protocol composition:
454+
// `protocol` `<` protocols `>`
448455
if (ChildrenCount >= 2) {
449456
auto Protocol = Type.getChild(0)->getAs<TokenSyntax>();
450457

@@ -472,6 +479,7 @@ TypeRepr *ASTGen::generate(UnknownTypeSyntax Type, SourceLoc &Loc) {
472479
}
473480
}
474481

482+
// Create ErrorTypeRepr for keywords.
475483
if (ChildrenCount == 1) {
476484
auto Keyword = Type.getChild(0)->getAs<TokenSyntax>();
477485
if (Keyword && isTokenKeyword(Keyword->getTokenKind())) {
@@ -480,6 +488,7 @@ TypeRepr *ASTGen::generate(UnknownTypeSyntax Type, SourceLoc &Loc) {
480488
}
481489
}
482490

491+
// Create empty TupleTypeRepr for types starting with `(`.
483492
if (ChildrenCount >= 1) {
484493
auto LParen = Type.getChild(0)->getAs<TokenSyntax>();
485494
if (LParen && LParen->getTokenKind() == tok::l_paren) {

0 commit comments

Comments
 (0)