Repository navigation
Conversation
For codes 14 to 19, Excel answers #VALUE! when k is an error read from a cell, a name, INDEX or INDIRECT, ahead of any error in the data; a computed error such as NA() or E1+0 stays itself. GridCraft passed the cell's error through. Fixes storytold#4277.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Upstream PR: storytold#4344 Head: 97d8313
Merges the zcode-pr-transfer branch (61 commits transferring open, not-yet-merged upstream PRs into our fork) into main. Docs (docs/ui-parity.md, docs/file-format-parity.md) resolved in favor of main's current changelog state; code from all transferred PRs carried over cleanly. Commits carried over (21 from this session + 40 earlier transfers): storytold#4408, storytold#4405, storytold#4406, storytold#4386, storytold#4379, storytold#4378, storytold#4376, storytold#4375, storytold#4373, storytold#4370, storytold#4369, storytold#4348, storytold#4347, storytold#4345, storytold#4344, storytold#4343, storytold#4341, storytold#4340, storytold#4337, storytold#4336, storytold#4318, storytold#4316, storytold#4315, storytold#4312, storytold#4310, storytold#4307, storytold#4306, storytold#4305, storytold#4303, storytold#4298, storytold#4295, storytold#4287, storytold#4286, storytold#4257, storytold#4256, storytold#4254, storytold#4252, storytold#4251, storytold#4248, storytold#4244, storytold#4243, storytold#4229, storytold#4228, storytold#4227, storytold#4225, storytold#4221, storytold#4220, storytold#4219, storytold#4217, storytold#4424, storytold#4423, storytold#4420, storytold#4419, storytold#4418, storytold#4414, storytold#3617, storytold#2642, storytold#2556, storytold#2321
Fixes #4277
What was wrong
For AGGREGATE codes 14 to 19,
subtotalincrates/calc/src/eval/reference_fns.rsreadkwithself.value, which dereferences a reference to the cell's value. An error in the k cell was then passed along as that error. Native Excel answers#VALUE!when k is an error reached through a reference: a cell, a defined name,INDEXorINDIRECT. It does so even when the data holds an error too. A computed error, such asNA()orE1+0, stays itself. The issue and its follow-up comment measure both kinds.The cell-versus-value distinction only exists in calc: by the time
aggregate_values_kingridcraft-functionssees k, it's a plain value. So the check is in calc.What changed
The k argument is evaluated with
eval, and the code notes whether the result was a reference before dereferencing it. If it was a reference and the value is an error, AGGREGATE returns#VALUE!before reading the data. Everything else is unchanged: computed k values, numeric k, codes 1 to 13, SUBTOTAL, and the cell budget.QA report
Main vs branch, end to end (
gridcraft-cli run, real cells)This is the issue's setup, plus its follow-up rows, built with
cell.setandformulas.defineName, printed, saved to.xlsx, and reopened withgridcraft-cli cat.mainis agridcraft-clibuilt fromorigin/main(19f07f3a); the branch is this PR (97d8313c). The Excel column is native Excel 16.0 as reported in the issue and its comment; I didn't run Excel myself.Setup:
A1:A4= 10, 20, 30, 40E1==NA(),E3==1/0,E4= 2C1:C2= 10,=1/0ErrorCellrefers to=Sheet1!$E$1=AGGREGATE(14,6,A1:A4,E1)=AGGREGATE(15,6,A1:A4,E3)=AGGREGATE(16…19,6,A1:A4,E1)=AGGREGATE(14,6,A1:A4,ErrorCell)=AGGREGATE(15,6,A1:A4,INDEX(E3:E4,1))=AGGREGATE(14,6,A1:A4,INDIRECT("E1"))=AGGREGATE(14,4,C1:C2,E1)(data error too, errors kept)=AGGREGATE(14,6,C1:C2,E1)(data error too, errors ignored)=AGGREGATE(14,6,A1:A4,E1+0)=AGGREGATE(14,6,A1:A4,NA())=AGGREGATE(15,6,A1:A4,INDEX(E3:E4,1)+0)=AGGREGATE(15,6,A1:A4,E4)(numeric k from a cell)=AGGREGATE(14,6,A1:A4,2)=AGGREGATE(9,6,A1:A4,E1)(code 9: E1 is data, skipped)=LARGE(A1:A4,E1)(not AGGREGATE)Both builds reopened their saved workbook with the same 18 values.
gridcraft-cli checkon the branch's file: 21 formula cells, 21 matched, round trip 0 of 1 files differ.Test
tests::aggregate_k_error_through_a_reference_is_value(crates/calc/src/tests.rs) covers:E1+0,NA()andINDEX(…)+0;The existing AGGREGATE tests in calc still pass, including the whole-column budget cases.
Negative control
With
reference_fns.rsfromorigin/mainand the new test kept (on top of97d8313c, then restored withgit checkout), the test fails at its first row:=AGGREGATE(14,6,A1:A4,E1), leftError(NA), rightError(Value).Gate (macOS arm64)
cargo fmt --all -- --checkcargo clippy -p gridcraft-calc -p gridcraft-functions --all-targets -- -D warningscargo test -p gridcraft-calc -p gridcraft-functions -p gridcraft-engineNot covered
AGGREGATE(14,6,A1:A4,E1:E2)) is AGGREGATE uses the first rank in a bare range instead of intersecting it with the formula cell #4276, about intersecting it with the formula's row. It isn't touched; a range that dereferences to an array goes through as before.AGGREGATE(14,4,C1:C2,NA())) still returns the data's error, as onmain. The issue doesn't measure it.cargo xtask ci: I didn't run the fullcargo xtask ci(wasm, layers, the other crates).Summary by CodeRabbit
AGGREGATEfunctions 14–19 so an error reached through a reference in the optionalkargument returns#VALUE!. Errors produced by calculations in that argument continue to return their original error.