diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 7a2028a174d..45fa313aec1 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -17,6 +17,7 @@ #include "swift/Parse/Parser.h" #include "swift/AST/Attr.h" #include "swift/AST/Decl.h" +#include "swift/Basic/Fallthrough.h" #include "swift/Basic/Version.h" #include "swift/Parse/Lexer.h" #include "swift/Parse/CodeCompletionCallbacks.h" @@ -519,6 +520,12 @@ ParserResult Parser::parseStmt() { (void)consumeIf(tok::kw_try, tryLoc); switch (Tok.getKind()) { + case tok::pound_line: + case tok::pound_sourceLocation: + assert((LabelInfo || tryLoc.isValid()) && + "unlabeled directives should be handled earlier"); + // Bailout, and let parseBraceItems() parse them. + SWIFT_FALLTHROUGH; default: diagnose(Tok, tryLoc.isValid() ? diag::expected_expr : diag::expected_stmt); return nullptr; @@ -543,14 +550,6 @@ ParserResult Parser::parseStmt() { if (LabelInfo) diagnose(LabelInfo.Loc, diag::invalid_label_on_stmt); if (tryLoc.isValid()) diagnose(tryLoc, diag::try_on_stmt, Tok.getText()); return parseStmtIfConfig(); - case tok::pound_line: - if (LabelInfo) diagnose(LabelInfo.Loc, diag::invalid_label_on_stmt); - if (tryLoc.isValid()) diagnose(tryLoc, diag::try_on_stmt, Tok.getText()); - return parseLineDirective(true); - case tok::pound_sourceLocation: - if (LabelInfo) diagnose(LabelInfo.Loc, diag::invalid_label_on_stmt); - if (tryLoc.isValid()) diagnose(tryLoc, diag::try_on_stmt, Tok.getText()); - return parseLineDirective(false); case tok::kw_while: if (tryLoc.isValid()) diagnose(tryLoc, diag::try_on_stmt, Tok.getText()); return parseStmtWhile(LabelInfo); diff --git a/test/Parse/line-directive.swift b/test/Parse/line-directive.swift index d21d3bb61f6..55a5d5bf428 100644 --- a/test/Parse/line-directive.swift +++ b/test/Parse/line-directive.swift @@ -31,3 +31,12 @@ public struct S { // expected-note{{in declaration of 'S'}} #sourceLocation() +// expected-error@+1 {{expected expression}} +try #sourceLocation(file: "try.swift", line: 100) +#sourceLocation() + +// expected-error@+3 {{expected statement}} +// expected-error@+2 {{#line directive was renamed to #sourceLocation}} +LABEL: +#line 200 "labeled.swift" +#sourceLocation()