diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/MoonP/moon_compiler.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index f18fb16..0028f22 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp | |||
@@ -389,14 +389,14 @@ private: | |||
389 | if (auto stmt = body->content.as<Statement_t>()) { | 389 | if (auto stmt = body->content.as<Statement_t>()) { |
390 | return stmt; | 390 | return stmt; |
391 | } else { | 391 | } else { |
392 | auto node = body->content.to<Block_t>()->statements.objects().back(); | 392 | const auto& stmts = body->content.to<Block_t>()->statements.objects(); |
393 | return static_cast<Statement_t*>(node); | 393 | return stmts.empty() ? nullptr : static_cast<Statement_t*>(stmts.back()); |
394 | } | 394 | } |
395 | } | 395 | } |
396 | 396 | ||
397 | Statement_t* lastStatementFrom(Block_t* block) { | 397 | Statement_t* lastStatementFrom(Block_t* block) { |
398 | auto node = block->statements.objects().back(); | 398 | const auto& stmts = block->statements.objects(); |
399 | return static_cast<Statement_t*>(node); | 399 | return stmts.empty() ? nullptr : static_cast<Statement_t*>(stmts.back()); |
400 | } | 400 | } |
401 | 401 | ||
402 | template <class T> | 402 | template <class T> |
@@ -3824,8 +3824,8 @@ private: | |||
3824 | transformAssignment(assignment, temp); | 3824 | transformAssignment(assignment, temp); |
3825 | } | 3825 | } |
3826 | if (returnValue) { | 3826 | if (returnValue) { |
3827 | auto stmt = lastStatementFrom(with->body); | 3827 | auto last = lastStatementFrom(with->body); |
3828 | if (!stmt->content.is<Return_t>()) { | 3828 | if (last && !last->content.is<Return_t>()) { |
3829 | temp.push_back(indent() + s("return "sv) + withVar + nll(with)); | 3829 | temp.push_back(indent() + s("return "sv) + withVar + nll(with)); |
3830 | } | 3830 | } |
3831 | } | 3831 | } |