tact
tact copied to clipboard
Function `writeExpression` in `writeExpression.ts` does not short-circuit on && and ||
Are you using the latest released (or pre-released, a.k.a. "next") version?
- [X] I'm using the latest Tact version
Tact source code
The first thing that function writeExpession does is to call the constant evaluator. If evaluation fails, it attempts to destruct the expression. In particular, for operators && and ||, it has these lines:
// Case for "&&" operator
if (f.op === "&&") {
return `( (${writeExpression(f.left, wCtx)}) ? (${writeExpression(f.right, wCtx)}) : (false) )`;
}
// Case for "||" operator
if (f.op === "||") {
return `( (${writeExpression(f.left, wCtx)}) ? (true) : (${writeExpression(f.right, wCtx)}) )`;
}
Hence, in the recursive call, it will always force evaluation of the second operand in && and ||. In other words, no short-circuiting happens for && and ||.
Relevant Tact/build system log output
No response
What happened?
No response
What did you expect?
For the particular case of && and ||, the recursive call should not call the constant evaluator.
Steps to reproduce
No response
How do you run Tact?
No response
Anything else?
Related to issue #886.