-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] compiler: catch argument shape errors
Steps to reproduce: - type in a cell `=IFERROR(ADD(A1:A2,1),456)` => the cell value is #ERROR instead of 456. The compiled formulas use to functions to get the values of references - `ref` returns a single value from a single cell - `range` returns a matrix of values Currently, the compiler chooses `ref` or `range` based on the function arg. e.g. for 'ADD(..., ...)', the compiler would choose `ref` because ADD only accepts single cell values. If the user typed `ADD(A1:A3, 2)`, `ref` currently checks the range size and throw an error if it's not a single cell. That causes the entire compiled function to fail. Notably: '=IFERROR(ADD(A1:A2,1), 45)' results in an error instead of 45. One key observation is that `ref` is actually useless from a functional POV. We could always use `range` no matter the shape of the arguments. There's already a check for the input sizes for each sub-function (think of 'ADD(TRANSPOSE(...), 5)'. There is a performance issue though because `range` always builds a 2D matrix. A POC was done to remove `ref` entirely and only use `range` but it showed 2x increase of the evaluation time of the large formula dataset. With this commit, we keep `ref` and use it every time the reference is a single cell, and (importantly) only in this case. The logic of errors =================== There are two types of errors in formulas: - structural/compilation errors: If the formula will *never* be correct, no matter what changes in the spreadsheet, for example `=TODAY(456)` will never work because `TODAY` will never accept any argument. Those errors cannot be caught by IFERROR for a functional reason: warn the user the formula is wrong (and will always be) and that he should fix it. - evaluation errors: Any other error (divisiion by zero, wrong type). They can be caught by IFERROR. In the context of this PR: `ADD(A1:A2,1)` is invalid because `ADD` does not accepts ranges. But it can become valid if row 2 is deleted. Task: 3859327 Part-of: #4088 Co-authored-by: Alexis Lacroix <[email protected]>
- Loading branch information
Showing
7 changed files
with
109 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.