-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Given the following branch node:
Expected Behaviour:
- The first time the branch is hit, the
ifclause is selected - The second time, the
elseif - The third time, the
else - And then the
elsefrom then on
Observed behaviour:
- First time, the
if - Second the, the
else(strange!!) - Third time, the
elseif - Each subsequent time, the
else
Why is this happening?
Based on what I can see of how the ID's are being used, when evaluating conditions in branches, the ID of the condition (meaning that specific clause) is being used rather than the ID of the owning branch node. That means it's actually counting the visits of each clause, not the branch node as a whole.
The observed behaviour now makes more sense.
During our first run through, the visit count of the if condition is 0, so we go through.
The second run, the if condition has a visit count of 1, so it fails. However, the visit count of the elseif clause is still 0 because we're counting the visits to the clause, not the whole node. So the visit count of elseif is 0, not 1, and so that fails and we fall down into the else.
On the third visit, the visit count of the elseif is now 1 since we evaluated it last round, so the elseif finally passes.
Is this intentional?
It's possible this is by design but it seems highly unintuitive.
Suggested Fix
When evaluating conditions in a branch node, have the visits() function return the visit count of the branch node itself rather than the individual clause. This may mean some restructuring because I don't think you actually ever count visit counts of branches since they're never transpiled.
Maybe a new TranspileBranch which just returns which output returned true?
Happy to discuss more.
