feat(calc): add implicit intersection and fix regex criteria anchoring#2268
feat(calc): add implicit intersection and fix regex criteria anchoring#2268xuri merged 5 commits intoqax-os:masterfrom
Conversation
Modified formulaCriteriaParser to wrap regex patterns with ^ and $. Prevents partial string matches in SUMIF/COUNTIF functions when wildcards are not explicitly used. Test verifies "administrative" matches exactly 2 cells, not 4 substring matches like "cyclical_flat_administrative".
Implements Excel's implicit intersection behavior where matrix arguments to scalar functions resolve to single cells based on formula position. Functions like ABS and IF now correctly handle range references in non-array formulas. Fixes regex criteria anchoring to prevent partial string matches in SUMIF/COUNTIF functions. Patterns now anchor properly at runtime rather than during parsing.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2268 +/- ##
=======================================
Coverage 99.56% 99.56%
=======================================
Files 32 32
Lines 26316 26322 +6
=======================================
+ Hits 26201 26207 +6
Misses 60 60
Partials 55 55
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Cover the error path (invalid cell name) and out-of-bounds row index branches to satisfy codecov patch coverage requirements.
There was a problem hiding this comment.
Pull request overview
This PR updates the calculation engine to better match Excel semantics by adding implicit intersection handling for certain scalar functions and adjusting how criteria regex anchoring is applied during SUMIF/COUNTIF-style evaluations.
Changes:
- Added
implicitIntersecthelper and applied it toABS,ISNUMBER, andIFto resolve matrix/range arguments to scalars. - Moved regex
^/$anchoring behavior intoformulaCriteriaEvalforcriteriaRegexp. - Added tests covering implicit intersection and criteria regex anchoring behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| calc.go | Adds implicitIntersect, applies it to functions, and changes regex anchoring logic in criteria evaluation. |
| calc_test.go | Adds new tests for implicit intersection and criteria anchoring behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
PR Details
Description
This PR implements two related fixes for the calculation engine:
Implicit Intersection: Adds
implicitIntersectmethod that resolves matrix arguments to scalar values based on the formula cell's row position. This matches Excel's behavior where range references in non-array formulas resolve to the cell in the same row as the formula. Applied toABS,ISNUMBER, andIFfunctions.Regex Criteria Anchoring Fix: Moves
^/$anchor insertion fromformulaCriteriaParsertoformulaCriteriaEval. The previous approach (anchoring at parse time) interfered with numeric criteria parsing since"^5$"cannot convert to a number. Anchoring at eval time preserves correctToNumber()behavior while still enforcing exact matching in SUMIF/COUNTIF.ISNUMBER matrix bug fix: The previous matrix handling code in
ISNUMBERhad a missingelsebranch, causing it to append bothtrueandfalsefor number cells, corrupting the output matrix. Replaced withimplicitIntersectfor correct scalar resolution.Related Issue
Fixes implicit intersection behavior for scalar functions receiving range/matrix arguments.
Motivation and Context
When a whole-column or range reference is passed to a scalar function like
ABS(A1:A5), Excel resolves it to the single cell in the same row as the formula cell (implicit intersection). Without this fix, the calculation engine could not handle these common spreadsheet patterns correctly. The regex anchoring fix ensures criteria-based functions (SUMIF, COUNTIF, etc.) correctly match exact values without breaking numeric criteria handling.How Has This Been Tested
TestCalcImplicitIntersect: validates ABS, ISNUMBER, and IF with range references across multiple rows, confirming each resolves to the correct row via implicit intersection (11 assertions)TestCalcCriteriaRegexpAnchoring: validates exact matching, wildcard patterns (*,?), and numeric criteria for SUMIF/COUNTIFTestCalcSUMIFExactMatch,TestCalcAVERAGEIF, andTestCalcCellValueTypes of changes
Checklist