Skip to content

Commit 5699820

Browse files
committed
Delayed function body parsing: replace two error handling code paths with asserts
This should just never happen. Swift SVN r6607
1 parent 258d4fd commit 5699820

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

Diff for: lib/Parse/ParseDecl.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1374,8 +1374,7 @@ bool Parser::parseDeclFuncBodyDelayed(FuncDecl *FD) {
13741374
"function body should be delayed");
13751375

13761376
auto FunctionParserState = State->takeBodyState(FE);
1377-
if (!FunctionParserState)
1378-
return false;
1377+
assert(FunctionParserState.get() && "should have a valid state");
13791378

13801379
auto BeginParserPosition = getParserPosition(FunctionParserState->BodyPos);
13811380
auto EndLexerState = L->getStateForEndOfTokenLoc(FE->getEndLoc());

Diff for: lib/Parse/PersistentParserState.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17+
#include "swift/AST/Expr.h"
1718
#include "swift/Parse/PersistentParserState.h"
1819

1920
using namespace swift;
@@ -31,12 +32,10 @@ void PersistentParserState::delayFunctionBodyParsing(FuncExpr *FE,
3132

3233
std::unique_ptr<PersistentParserState::FunctionBodyState>
3334
PersistentParserState::takeBodyState(FuncExpr *FE) {
34-
std::unique_ptr<FunctionBodyState> State;
35+
assert(FE->getBodyKind() == FuncExpr::BodyKind::Unparsed);
3536
DelayedBodiesTy::iterator I = DelayedBodies.find(FE);
36-
if (I != DelayedBodies.end()) {
37-
State = std::move(I->second);
38-
DelayedBodies.erase(I);
39-
}
40-
37+
assert(I != DelayedBodies.end() && "State should be saved");
38+
std::unique_ptr<FunctionBodyState> State = std::move(I->second);
39+
DelayedBodies.erase(I);
4140
return State;
4241
}

0 commit comments

Comments
 (0)