1
0
mirror of synced 2024-11-12 10:10:53 +01:00

patterns: Prevent division by zero

This commit is contained in:
WerWolv 2021-03-02 22:55:23 +01:00
parent a91afdb6ae
commit 8646fb4487

View File

@ -232,8 +232,12 @@ namespace hex::lang {
case Token::Operator::Star:
return new ASTNodeIntegerLiteral({ newType, leftValue * rightValue });
case Token::Operator::Slash:
if (rightValue == 0)
this->getConsole().abortEvaluation("Division by zero");
return new ASTNodeIntegerLiteral({ newType, leftValue / rightValue });
case Token::Operator::Percent:
if (rightValue == 0)
this->getConsole().abortEvaluation("Division by zero");
return new ASTNodeIntegerLiteral({ newType, modulus(leftValue, rightValue) });
case Token::Operator::ShiftLeft:
return new ASTNodeIntegerLiteral({ newType, shiftLeft(leftValue, rightValue) });