No longer consider an equation of the form “x(+1) = 0” as defining x to be a constant

Fix this by restricting the detection of constant equations to those where the
variable appears without a lead or lag.

Closes: #83
(cherry picked from commit 1cc512962c)
5.x
Sébastien Villemot 2021-11-19 18:01:11 +01:00
parent 008a0dbb9e
commit bdbafdc34c
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
1 changed files with 7 additions and 4 deletions

View File

@ -5469,10 +5469,13 @@ BinaryOpNode::findConstantEquations(map<VariableNode *, NumConstNode *> &table)
{
if (op_code == BinaryOpcode::equal)
{
if (dynamic_cast<VariableNode *>(arg1) && dynamic_cast<NumConstNode *>(arg2))
table[dynamic_cast<VariableNode *>(arg1)] = dynamic_cast<NumConstNode *>(arg2);
else if (dynamic_cast<VariableNode *>(arg2) && dynamic_cast<NumConstNode *>(arg1))
table[dynamic_cast<VariableNode *>(arg2)] = dynamic_cast<NumConstNode *>(arg1);
// The variable must be contemporaneous (see #83)
if (auto varg1 = dynamic_cast<VariableNode *>(arg1);
varg1 && varg1->lag == 0 && dynamic_cast<NumConstNode *>(arg2))
table[varg1] = dynamic_cast<NumConstNode *>(arg2);
else if (auto varg2 = dynamic_cast<VariableNode *>(arg2);
varg2 && varg2->lag == 0 && dynamic_cast<NumConstNode *>(arg1))
table[varg2] = dynamic_cast<NumConstNode *>(arg1);
}
}