Skip to content

Commit 3e98b04

Browse files
committed
fix: Crash when evaluating a void expression as a math expression
1 parent 477228f commit 3e98b04

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/source/pl/core/ast/ast_node_mathematical_expression.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ namespace pl::core::ast {
5151

5252
ASTNodeMathematicalExpression::ASTNodeMathematicalExpression(const ASTNodeMathematicalExpression &other) : ASTNode(other) {
5353
this->m_operator = other.m_operator;
54-
this->m_left = other.m_left->clone();
55-
this->m_right = other.m_right->clone();
54+
this->m_left = other.m_left == nullptr ? nullptr : other.m_left->clone();
55+
this->m_right = other.m_right == nullptr ? nullptr : other.m_right->clone();
5656
}
5757

5858
[[nodiscard]] std::unique_ptr<ASTNode> ASTNodeMathematicalExpression::evaluate(Evaluator *evaluator) const {
5959
[[maybe_unused]] auto context = evaluator->updateRuntime(this);
6060

6161
if (this->getLeftOperand() == nullptr || this->getRightOperand() == nullptr)
62-
err::E0002.throwError("Void expression used in ternary expression.", "If you used a function for one of the operands, make sure it returned a value.", this->getLocation());
62+
err::E0002.throwError("Cannot evaluate void expression", "Did you try to work with the result of a function that didn't return anything?", this->getLocation());
6363

6464
const auto throwInvalidOperandError = [this]() -> ASTNode * {
6565
err::E0002.throwError("Invalid operand used in mathematical expression.", { }, this->getLocation());

lib/source/pl/pattern_language.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ namespace pl {
269269
if (node == nullptr)
270270
continue;
271271

272-
auto location = node->getLocation();
272+
const auto &location = node->getLocation();
273273
if (lastLine == location.line)
274274
continue;
275275

0 commit comments

Comments
 (0)