[Parse] Let #sourceLocation be parsed in parseBraceItems()

Returning 'makeParserSuccess()' as a 'ParserResult<Stmt>' causes assertion error.

  Assertion `Status.isError()' failed
This commit is contained in:
Rintaro Ishizaki
2016-12-06 22:03:36 +09:00
parent 79079623bc
commit 54efbbbf87
2 changed files with 16 additions and 8 deletions

View File

@@ -17,6 +17,7 @@
#include "swift/Parse/Parser.h" #include "swift/Parse/Parser.h"
#include "swift/AST/Attr.h" #include "swift/AST/Attr.h"
#include "swift/AST/Decl.h" #include "swift/AST/Decl.h"
#include "swift/Basic/Fallthrough.h"
#include "swift/Basic/Version.h" #include "swift/Basic/Version.h"
#include "swift/Parse/Lexer.h" #include "swift/Parse/Lexer.h"
#include "swift/Parse/CodeCompletionCallbacks.h" #include "swift/Parse/CodeCompletionCallbacks.h"
@@ -519,6 +520,12 @@ ParserResult<Stmt> Parser::parseStmt() {
(void)consumeIf(tok::kw_try, tryLoc); (void)consumeIf(tok::kw_try, tryLoc);
switch (Tok.getKind()) { 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: default:
diagnose(Tok, tryLoc.isValid() ? diag::expected_expr : diag::expected_stmt); diagnose(Tok, tryLoc.isValid() ? diag::expected_expr : diag::expected_stmt);
return nullptr; return nullptr;
@@ -543,14 +550,6 @@ ParserResult<Stmt> Parser::parseStmt() {
if (LabelInfo) diagnose(LabelInfo.Loc, diag::invalid_label_on_stmt); if (LabelInfo) diagnose(LabelInfo.Loc, diag::invalid_label_on_stmt);
if (tryLoc.isValid()) diagnose(tryLoc, diag::try_on_stmt, Tok.getText()); if (tryLoc.isValid()) diagnose(tryLoc, diag::try_on_stmt, Tok.getText());
return parseStmtIfConfig(); 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: case tok::kw_while:
if (tryLoc.isValid()) diagnose(tryLoc, diag::try_on_stmt, Tok.getText()); if (tryLoc.isValid()) diagnose(tryLoc, diag::try_on_stmt, Tok.getText());
return parseStmtWhile(LabelInfo); return parseStmtWhile(LabelInfo);

View File

@@ -31,3 +31,12 @@ public struct S { // expected-note{{in declaration of 'S'}}
#sourceLocation() #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()