patterns: Evaluate return value before setting control flow type

Fixes another issue mentioned in #460
This commit is contained in:
WerWolv 2022-03-01 20:37:15 +01:00
parent 2c361f9b0a
commit 61d9918dae
1 changed files with 11 additions and 9 deletions

View File

@ -34,18 +34,20 @@ namespace hex::pl {
}
FunctionResult execute(Evaluator *evaluator) const override {
evaluator->setCurrentControlFlowStatement(this->m_type);
if (this->m_rvalue == nullptr)
if (this->m_rvalue == nullptr) {
evaluator->setCurrentControlFlowStatement(this->m_type);
return std::nullopt;
} else {
auto returnValue = this->m_rvalue->evaluate(evaluator);
auto literal = dynamic_cast<ASTNodeLiteral *>(returnValue.get());
auto returnValue = this->m_rvalue->evaluate(evaluator);
auto literal = dynamic_cast<ASTNodeLiteral *>(returnValue.get());
evaluator->setCurrentControlFlowStatement(this->m_type);
if (literal == nullptr)
return std::nullopt;
else
return literal->getValue();
if (literal == nullptr)
return std::nullopt;
else
return literal->getValue();
}
}
private: