invalid #CIRC_REFERENCE

Hi,

If for example you enter the following data:
A1: 2
B1: =A13
C1: =B1+A1
4
Then it will correctly display 2, 6, 14 in A1, B2 and C1. However if you now change A1 to 3 you will get ‘#CIRC_REFERENCE’ in C1, but there is no circular reference. C1 reference A1 twice (once directly and once indirectly through B1) but this is no circular reference and it is no error.
I believe the algorithm you want to use is:

  • Do a depth-first traversal of triggers to calculate all values along the way
  • At each node check if the node already exist in a stack, if so report ‘#CIRC_REFERENCE’ otherwise push it to the stack and continue the depth-first traversal.
    The problem with your code is that you don’t pop the node once you are done with it so if you visit the same node again in a parallel branch of the depth-first traversal it will incorrectly be reported as ‘#CIRC_REFERENCE’. The patch below fixes this.

Thanks,
Erik

--- a/installer/src/codebase/php/api.php
+++ b/installer/src/codebase/php/api.php
@@ -446,6 +446,7 @@ class SpreadSheetCell {
                if ($this->calc === '#CIRC_REFERENCE') return $response;
                SpreadSheet::$processed[$coord] = true;
                $response = array_merge($response, $this->run_triggers());
+               unset(SpreadSheet::$processed[$coord]);
                return $response;
        }

Thanks for the patch
We will include it in the main codebase.

thank you, I had the same issue with dhtmlx on my website and this seems to have fixed it.
-Louis