17
17
#include " swift/Parse/Parser.h"
18
18
#include " swift/AST/Attr.h"
19
19
#include " swift/AST/Decl.h"
20
+ #include " swift/Basic/Fallthrough.h"
20
21
#include " swift/Basic/Version.h"
21
22
#include " swift/Parse/Lexer.h"
22
23
#include " swift/Parse/CodeCompletionCallbacks.h"
@@ -519,6 +520,13 @@ ParserResult<Stmt> Parser::parseStmt() {
519
520
(void )consumeIf (tok::kw_try, tryLoc);
520
521
521
522
switch (Tok.getKind ()) {
523
+ case tok::pound_line:
524
+ case tok::pound_sourceLocation:
525
+ case tok::pound_if:
526
+ assert ((LabelInfo || tryLoc.isValid ()) &&
527
+ " unlabeled directives should be handled earlier" );
528
+ // Bailout, and let parseBraceItems() parse them.
529
+ SWIFT_FALLTHROUGH;
522
530
default :
523
531
diagnose (Tok, tryLoc.isValid () ? diag::expected_expr : diag::expected_stmt);
524
532
return nullptr ;
@@ -539,18 +547,6 @@ ParserResult<Stmt> Parser::parseStmt() {
539
547
if (LabelInfo) diagnose (LabelInfo.Loc , diag::invalid_label_on_stmt);
540
548
if (tryLoc.isValid ()) diagnose (tryLoc, diag::try_on_stmt, Tok.getText ());
541
549
return parseStmtGuard ();
542
- case tok::pound_if:
543
- if (LabelInfo) diagnose (LabelInfo.Loc , diag::invalid_label_on_stmt);
544
- if (tryLoc.isValid ()) diagnose (tryLoc, diag::try_on_stmt, Tok.getText ());
545
- return parseStmtIfConfig ();
546
- case tok::pound_line:
547
- if (LabelInfo) diagnose (LabelInfo.Loc , diag::invalid_label_on_stmt);
548
- if (tryLoc.isValid ()) diagnose (tryLoc, diag::try_on_stmt, Tok.getText ());
549
- return parseLineDirective (true );
550
- case tok::pound_sourceLocation:
551
- if (LabelInfo) diagnose (LabelInfo.Loc , diag::invalid_label_on_stmt);
552
- if (tryLoc.isValid ()) diagnose (tryLoc, diag::try_on_stmt, Tok.getText ());
553
- return parseLineDirective (false );
554
550
case tok::kw_while:
555
551
if (tryLoc.isValid ()) diagnose (tryLoc, diag::try_on_stmt, Tok.getText ());
556
552
return parseStmtWhile (LabelInfo);
0 commit comments