Inline arrays don't watch their dependencies (previously: Volatile formulas not recalculating array dependencies)
This is quite a big bug I think as the root cause of it is arrays are not being processed in the dependencies. This means that there are likely other bugs caused by this.
The following unit test fails when it should pass.
volatile-functions.spec.ts
it('array cell which is dependent on volatile formula is also recomputed', () => {
const engine = HyperFormula.buildFromArray([
['=RAND()', '42', '={A1}'],
])
const valueBeforeRecomputation = engine.getCellValue(adr('C1'))
engine.setCellContents(adr('B1'), '35')
expect(engine.getCellValue(adr('C1'))).not.toEqual(valueBeforeRecomputation)
})
Fix:
collectDependencies.ts
case AstNodeType.ARRAY: {
ast.args.forEach((arrArg: Ast[]) => {
arrArg.forEach((ast) =>
collectDependenciesFn(ast, functionRegistry, dependenciesSet, needArgument)
)
})
return
}
As a side node, I checked all the other AST's to see if any others were missing in collect-dependencies file.
They all exist apart from: ERROR_WITH_RAW_INPUT.
However this is probably fine as it will not have any dependencies on it anyway. Maybe that should be explicility returned in the function though, same as EMPTY, NUMBER, STRING, ERROR is. Or a default case provided.
An inline array ({...}) behaves like a constant. Its value is never recomputed after initialization. This limitation is not described in our documentation but soon will be: https://github.com/handsontable/hyperformula/pull/985
@MartinDawson Can you describe your use case that requires inline arrays to "watch" its dependencies? We might consider changing this behaviour.
@sequba I'm not working with hyperformula anymore but as far as I can remember google sheets & Excel do re-calculate the dependency.
Also it's just bad UX to not recalculate it as a user would always want the dependency to change if a child volatile changes imo
@MartinDawson thanks for your input. We decided that a new configuration flag will be introduced to control this behaviour.