Skip to content

Fix scalar lookup edge cases - #95

Open
Harrison-Booth wants to merge 675 commits into
mainfrom
gc-lookup-scalar
Open

Harrison-Booth wants to merge 675 commits into
mainfrom
gc-lookup-scalar

Conversation

@Harrison-Booth

@Harrison-Booth Harrison-Booth commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Make MATCH, VLOOKUP and HLOOKUP return #N/A for scalar lookup arrays.
  • Reject scalar and array values in AGGREGATE's reference form for function numbers 1–13.
  • Convert HYPERLINK's default display value to text.
  • Add regression tests and update the function parity notes.

Excel results

Measured with Excel on Windows using a fresh temporary workbook for each formula. Each workbook was closed without saving.

Formula Excel result
MATCH(1,1) #N/A
VLOOKUP(1,1,1) #N/A
HLOOKUP(1,1,1) #N/A
AGGREGATE(1,1,1) #VALUE!
AGGREGATE(1,6,{1,2}) #VALUE!
HYPERLINK(1) Text 1
ISTEXT(HYPERLINK(1)) TRUE

Validation

  • cargo fmt --check passed.
  • Rust tests were not run.

Summary by CodeRabbit

  • Bug Fixes
    • AGGREGATE now returns #VALUE! when reference-form calls receive a scalar or array value instead of a reference, while propagating input errors.
    • VLOOKUP and HLOOKUP now return #N/A for scalar lookup tables. MATCH returns #N/A for scalar lookup arrays; references and array values remain supported, and input errors continue to propagate.
    • HYPERLINK now returns its link value as text, including when the link is numeric.
  • Documentation
    • Updated the function compatibility notes and revision history with the verified behavior.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

No actionable comments were generated in the recent review.

Walkthrough

The changes update input handling for AGGREGATE, VLOOKUP, HLOOKUP, and MATCH. They also make HYPERLINK return text and update related tests and function parity notes.

Changes: Function input handling

Layer / File(s) Summary
AGGREGATE reference arguments
crates/calc/src/eval/reference_fns.rs, crates/calc/src/tests.rs
For AGGREGATE function numbers 1–13, value arguments now propagate errors or return #VALUE!. Tests cover a scalar, an array constant, and an invalid reference that returns #REF!.
Lookup array validation
crates/functions/src/lookup.rs
VLOOKUP and HLOOKUP return #N/A for scalar tables. MATCH returns #N/A for scalar lookup arrays. Errors continue to propagate, and references and arrays remain supported. Tests cover scalar VLOOKUP and HLOOKUP inputs.
HYPERLINK text output and parity notes
crates/functions/src/info.rs, docs/function-parity.md
HYPERLINK returns its link argument as text after the existing error check and empty-to-zero conversion. Tests check numeric link output and ISTEXT. The parity notes record these function changes and state that the listed cases were checked in Excel for Microsoft 365 on Windows.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: aiongg, echelon, marcoarnulfo

Merge Risk: Minimal · previous review e4045

The spreadsheet-function behavior matches the documented Excel parity changes, with no identified merge-blocking risk.

Security architecture risk: Minimal · up to e4045

The changes narrow accepted spreadsheet inputs and normalize default hyperlink display values. No new access, privileges, or material security risk was identified in the reviewed changes.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated exposure change is limited to formula results and early error termination for the affected functions. The changed branches restrict accepted values or convert display text; they do not introduce a new privileged operation or expand reference traversal.

Trust Boundaries and Controls

  • observed — The lookup guards use the existing from_ref argument-provenance flag, not a new identity or authorization mechanism. The AGGREGATE rejection produces an ordinary spreadsheet error through the unchanged evaluator error wrapper.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title is concise and accurately describes the scalar lookup changes in MATCH, VLOOKUP, and HLOOKUP. It does not mention the additional AGGREGATE and HYPERLINK changes, but it still reflects a prim…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title is concise and accurately describes the scalar lookup changes in MATCH, VLOOKUP, and HLOOKUP. It does not mention the additional AGGREGATE and HYPERLINK changes, but it still reflects a primary part of the pull request.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 4 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 852cbe6 and e4045de.

Files selected for processing: 2
  • crates/calc/src/eval/reference_fns.rs
  • crates/calc/src/tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

echelon and others added 29 commits October 30, 2026 23:03
# Conflicts:
#	docs/function-parity.md
# Conflicts:
#	crates/functions/src/text.rs
#	docs/function-parity.md
# Conflicts:
#	docs/function-parity.md
# Conflicts:
#	crates/functions/src/stat/tests.rs
#	docs/function-parity.md
# Conflicts:
#	crates/functions/src/stat/tests.rs
#	docs/function-parity.md
# Conflicts:
#	crates/functions/src/stat/tests.rs
#	docs/function-parity.md
# Conflicts:
#	docs/function-parity.md
# Conflicts:
#	crates/functions/src/stat/tests.rs
#	docs/function-parity.md
# Conflicts:
#	docs/function-parity.md
# Conflicts:
#	docs/function-parity.md
# Conflicts:
#	docs/function-parity.md
…o eu-strip)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eu-strip)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… Preview)

A sheet's view is not an undo step: Excel doesn't undo a switch between
Normal, Page Layout and Page Break Preview, and view.normal,
view.pageLayout and view.pageBreakPreview are noundo here. But undo and
redo swap in a whole snapshot of the workbook, so undoing an earlier edit
put back the view the sheet had then: set A1, switch to Page Break
Preview, undo, and the sheet was in Normal again (redo switched it back).

Undo and redo now keep each sheet's current view (extra::keep_view_modes),
as they already keep the Watch Window list, carrying it through each step
of a multi-step undo or redo. Sheets are matched by name; while a rename
is undone or redone, by position under the name the restored snapshot
doesn't have. A view kept this way doesn't make a saved
workbook dirty, as set_view doesn't.

Tests: undo and redo with each view, undoing a rename and a new sheet, a
rename and a new sheet undone and redone with steps: 2, and redo back to
the saved state staying clean. Each fails without the change (the view
reverted to Normal).
…undo difference

The view commands are not undo steps and don't mark the workbook changed (as in
Excel), so undoing everything leaves a sheet's view mode as it is. The undo
check now resets the view mode with the other view state before comparing.
Seed 177 (`view.pageBreakPreview` on the sales sample) failed the [undo]
invariant without this.
Updates: shared check-result dialog from craft-update
docs: tidy agent, contributor and asset docs
The Function Library group was a big Insert Function button followed by
AutoSum and seven big category buttons that all drew the same icon, the
widest group on the Formulas tab. It is now laid out as Excel lays it
out when the window is not wide enough for a big button per category:
big Insert Function and AutoSum buttons, then the categories as
labelled small buttons in columns of three:

  Recently Used    Text                 Math & Trig
  Financial        Date & Time          More Functions
  Logical          Lookup & Reference

- The category buttons draw a new code-drawn icon, Icon::FnBook, a book
  whose spine and glyph (star, coins, question mark, letter, clock,
  magnifier, theta, dots) take the category's colour from the theme's
  category palette. icons::paint_accent draws an icon with an accent
  colour, and widgets::small_button_accent is a small button that uses
  it; small_button is unchanged for its callers.
- AutoSum stays the big split button: the icon inserts SUM, the label
  and arrow open the AutoSum menu, which now reads Sum, Average, Count
  Numbers, Max, Min and More Functions… and is shared with Home ›
  Editing. Its tooltip names the control only, so the shortcut comes
  from the platform lookup (Alt+= on Windows and Linux).
- Each category menu lists its functions with their descriptions on
  hover and ends with Insert Function…, which opens the dialog with
  that category. More Functions cascades into Statistical, Engineering,
  Cube, Information, Compatibility and Web. Recently Used lists what
  the engine's formulas.recentlyUsed returns.
- The function categories, the function list (built once) and the menus
  live in a new function_library module; the dialog's category labels
  come from it.
- keytips.json gains MR for Recently Used, Excel's sequence. Labelled
  small and big buttons report their label to accessibility.
- The one-line labels (Date & Time, Lookup & Reference, Math & Trig,
  More Functions) replace the two-line keys in every interface
  language, with the same words. Recently Used is translated in Czech,
  German, Spanish, French, Japanese, Korean, Portuguese, Russian and
  Chinese; the other languages show it in English, their fallback.

Tests: tests/it/function_library.rs covers the layout (columns of three
level with the tab's other columns), each category menu and its Insert
Function… row, the More Functions cascade, the AutoSum split button and
its menu, and the MR key tip. A ribbon unit test keeps Command-key
glyphs out of the ribbon's text. chart_resize picks the chart menu's
Delete now that Home › Cells' Delete has an accessible name.
…ategory list

formulas.recentlyUsed scanned the session journal for cell.set inputs.
It missed formulas entered by range.* commands, lost them when the
journal dropped its oldest entries (a large file open or a long script
is enough), and started empty in every session. The Function Library's
Recently Used menu and the Insert Function dialog list what it returns.

- Prefs::recent_functions (a new engine module, recent.rs) holds the
  ten functions most recently entered in a formula, newest first.
  Session::execute updates it for every cell.* and range.* command it
  journals, from any source (the interface, the control channel, MCP or
  a script). It reads at most 2,000 of the formulas a command enters,
  starting from the last one; formulas longer than Excel's limit are
  skipped. formulas.recentlyUsed
  returns it. It never reads the journal back, so the journal's caps do
  not affect it.
- The list is kept with the other engine preferences (prefs.json, the
  browser's storage on the web), so it survives a restart as Excel's
  does. It is read leniently: a malformed value loses only this list. A
  fresh install starts from common functions.

The Insert Function dialog is titled "Insert Function", as in Excel (it
said "Formula Builder"), and gains a working category list: Most
Recently Used, All, then each category in Excel's order. A category may
be given by label or by engine id, so a Function Library menu or the
control channel (ui.dialog.set) opens it on one, and a new search
switches to All. The dialog keeps its translated labels and its search
in the interface language. Each row shows the function's name and its
category in two columns; the category column starts after the widest
name shown, so a long name in any font or formula language stays clear
of it. A function counts as recently used once its formula is entered,
not when OK is pressed. The unused "Formula Builder" translations are
removed.

Tests: engine unit tests for reading functions from formulas (strings,
unknown names, over-long and malformed formulas), the formulas a
command enters (newest first, within the budget), the ten-name list
and the lenient read of prefs.json; tests/it/recently_used.rs for
cell.set and range.setValues from the session, a failed command, a
cleared journal and a save and reload of the preferences. UI tests for
the menu's order and the dialog's title, categories, engine-id
category, search and OK, and for the category column with a wide font.
The search box asked for the keyboard focus every frame, so Tab moved to the
category list for one frame and the focus went back to the search box. The
dialog now gives the search box the focus once, when it opens, through the
module's take_first_focus, as the other dialogs do.

Test: insert_function_lets_tab_reach_the_category_list (the search box has
the focus and takes typing; after Tab the category list keeps it over several
frames; Space opens the list).
echelon and others added 30 commits November 3, 2026 09:55
…ytold#3252, storytold#3239, storytold#3244 and storytold#3268

- storytold#3223: sniff the first 64 KiB for a web page and skip JSON and files over the text-import cap, so
  every CSV/TSV is no longer decoded in full before the size check.
- storytold#3253: SYLK relative offsets use checked arithmetic (no overflow on R[9223372036854775807]); at
  most 1024 column-width records are kept; regression test.
- storytold#3254: a single selected merged cell searches the whole sheet, as one selected cell does.
- storytold#3252: the formula bar's height cap is half the room below the ribbon, not half the window, so
  the worksheet stays visible in a short window (CodeRabbit Major).
- storytold#3239, storytold#3244, storytold#3252, storytold#3268: es/de/cs/zh/ko/ru/pt entries for the new interface strings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… room for the worksheet)

# Conflicts:
#	crates/ui-egui/src/formula_bar.rs
…orytold#3211)

Importing a workbook whose sheets share a name rescanned every sheet for
every suffix tried, so a file of repeated names opened in cubic time.
SheetNames keeps the assigned names and the next suffix per stem.
wrap_lines split an over-long word by re-measuring and copying the
rest of the word for every piece it cut, and only checked its line
limit once the word was done, so one long word in a narrow text box
cost word length x pieces. Each new word also re-measured the whole
line built so far.

Line and piece widths are now running sums of glyph widths (the same
sum text_width makes), so every character is measured once, and the
line limit is checked while a word is being split. The lines produced
are unchanged; a test compares them with the old wrapper.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.