tact icon indicating copy to clipboard operation
tact copied to clipboard

Function `writeExpression` in `writeExpression.ts` does not short-circuit on && and ||

Open jeshecdom opened this issue 4 months ago • 0 comments

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.

jeshecdom avatar Oct 02 '24 12:10 jeshecdom