xlstream-eval: bound VLOOKUP and INDEX col index to range width#186
Merged
Conversation
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: bb31644 | Previous: c90c6b8 | Ratio |
|---|---|---|---|
arithmetic/concat |
258 ns/iter (± 13) |
210 ns/iter (± 2) |
1.23 |
This comment was automatically generated by workflow using github-action-benchmark.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #143
Problem
builtin_vlookupandbuiltin_indexextractedstart_colfrom the table/rangeRangeRefbut ignoredend_col. Acol_index/col_numpast the range's last column read neighboring data from the loaded lookup sheet instead of returning#REF!. Example:=VLOOKUP(1, Lookup!A:A, 2, FALSE)returned column B's value instead of#REF!.Fix
Both functions now capture
end_col, compute the declared range width (end_col - start_col + 1), and return#REF!when the column index exceeds it — matching Excel. The check is skipped whenend_colisNone(whole-row refs already fail thestart_col: Some(..)guard).Changes
crates/xlstream-eval/src/builtins/lookup.rs: captureend_colin VLOOKUP and INDEX destructures; add a width bound check returning#REF!for out-of-range column indices.vlookup_col_index_past_range_returns_ref,vlookup_col_index_at_range_width_ok,index_col_past_range_returns_ref.issue-143-lookup-range-bounds.xlsx(Excel-populated): 38 formula cells across 5 rows covering valid lookups,#REF!(col past 1-col and 3-col ranges, both functions), plus#N/A(miss) and#VALUE!(col_index 0) singletons.Scope note
The fix targets column bounds, as the issue describes. INDEX with a row past the loaded data of a whole-column range (
INDEX(A:C, 100, 1)) is a separate concern: Excel treats it as in-range-empty (0) while xlstream returns#REF!(it only loads actual data rows). That deviation is pre-existing and intentional (see the existingindex_out_of_boundsunit test), so it is out of scope here and excluded from the fixture.Test plan
cargo test -p xlstream-evalpasses (2265 lib + 137 doc, no regressions)make checkpassesCloses #143