@@ -408,34 +408,31 @@ ParserStatus Parser::parseBraceItems(SmallVectorImpl<ASTNode> &Entries,
408
408
}
409
409
}
410
410
}
411
- } else {
411
+ } else if (Tok. is (tok::kw_init) && isa<ConstructorDecl>(CurDeclContext)) {
412
412
SourceLoc StartLoc = Tok.getLoc ();
413
- if (Tok.is (tok::kw_init)) {
414
- if (auto CD = dyn_cast<ConstructorDecl>(CurDeclContext)) {
415
- // Hint at missing 'self.' or 'super.' then skip this statement.
416
- bool isConvenient = CD->isConvenienceInit ();
417
- diagnose (StartLoc, diag::invalid_nested_init, isConvenient)
418
- .fixItInsert (StartLoc, isConvenient ? " self." : " super." );
419
- NeedParseErrorRecovery = true ;
420
- }
421
- } else {
422
- ParserStatus ExprOrStmtStatus = parseExprOrStmt (Result);
423
- BraceItemsStatus |= ExprOrStmtStatus;
424
- if (ExprOrStmtStatus.isError ())
425
- NeedParseErrorRecovery = true ;
426
- diagnoseDiscardedClosure (*this , Result);
427
- if (ExprOrStmtStatus.isSuccess () && IsTopLevel) {
428
- // If this is a normal library, you can't have expressions or
429
- // statements outside at the top level.
430
- diagnose (StartLoc,
431
- Result.is <Stmt*>() ? diag::illegal_top_level_stmt
432
- : diag::illegal_top_level_expr);
433
- Result = ASTNode ();
434
- }
435
-
436
- if (!Result.isNull ())
437
- Entries.push_back (Result);
413
+ auto CD = cast<ConstructorDecl>(CurDeclContext);
414
+ // Hint at missing 'self.' or 'super.' then skip this statement.
415
+ bool isConvenient = CD->isConvenienceInit ();
416
+ diagnose (StartLoc, diag::invalid_nested_init, isConvenient)
417
+ .fixItInsert (StartLoc, isConvenient ? " self." : " super." );
418
+ NeedParseErrorRecovery = true ;
419
+ } else {
420
+ ParserStatus ExprOrStmtStatus = parseExprOrStmt (Result);
421
+ BraceItemsStatus |= ExprOrStmtStatus;
422
+ if (ExprOrStmtStatus.isError ())
423
+ NeedParseErrorRecovery = true ;
424
+ diagnoseDiscardedClosure (*this , Result);
425
+ if (ExprOrStmtStatus.isSuccess () && IsTopLevel) {
426
+ // If this is a normal library, you can't have expressions or
427
+ // statements outside at the top level.
428
+ diagnose (Tok.getLoc (),
429
+ Result.is <Stmt*>() ? diag::illegal_top_level_stmt
430
+ : diag::illegal_top_level_expr);
431
+ Result = ASTNode ();
438
432
}
433
+
434
+ if (!Result.isNull ())
435
+ Entries.push_back (Result);
439
436
}
440
437
441
438
if (!NeedParseErrorRecovery && !PreviousHadSemi && Tok.is (tok::semi)) {
0 commit comments