mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -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<Stmt> 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<Stmt> 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);
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user