Skip to content

fix: respect defaultValue when arg is AstNodeType.EMPTY#1630

Closed
marcin-kordas-hoc wants to merge 1 commit intohandsontable:developfrom
marcin-kordas-hoc:fix/empty-default-value
Closed

fix: respect defaultValue when arg is AstNodeType.EMPTY#1630
marcin-kordas-hoc wants to merge 1 commit intohandsontable:developfrom
marcin-kordas-hoc:fix/empty-default-value

Conversation

@marcin-kordas-hoc
Copy link
Collaborator

@marcin-kordas-hoc marcin-kordas-hoc commented Mar 5, 2026

Problem

When a user writes an empty argument (e.g. =VLOOKUP(2,A1:B3,2,)), the parser
produces AstNodeType.EMPTY which evaluates to EmptyValue (a Symbol sentinel).

The guard in FunctionPlugin.coerceArgumentsToRequiredTypes checked only for
undefined, so EmptyValue passed through and was coerced to 0/false instead
of using the parameter's declared defaultValue.

Affected functions: any plugin parameter with defaultValue ≠ 0/false
(e.g. LOG base=10, VLOOKUP/HLOOKUP sorted=true, MATCH matchType=1, ADDRESS abs=1).

Fix

In FunctionPlugin.coerceArgumentsToRequiredTypes: when the runtime value is
EmptyValue and the parameter declares an explicit defaultValue, substitute
defaultValue instead of passing EmptyValue to type coercion.

Tests

Regression tests in companion PR in handsontable/hyperformula-tests
(branch fix/empty-default-value): covers VLOOKUP, HLOOKUP, MATCH, ADDRESS, LOG.


Note

Medium Risk
Touches shared function-argument coercion used by all formula plugins, so behavior changes may surface broadly, but the change is narrow and gated to EmptyValue with an explicit defaultValue.

Overview
Fixes argument coercion so explicitly empty arguments (parsed as AstNodeType.EMPTYEmptyValue) are treated like “missing” when a parameter defines a defaultValue.

In FunctionPlugin.coerceArgumentsToRequiredTypes, EmptyValue now substitutes the corresponding defaultValue (when provided) before type coercion, preventing empty trailing args from being coerced into 0/false for functions like LOG, VLOOKUP/HLOOKUP, MATCH, and ADDRESS.

Written by Cursor Bugbot for commit f68ecd8. This will update automatically on new commits. Configure here.

When a user writes an empty argument (e.g. =FUNC(a,,c)), the parser produces
AstNodeType.EMPTY which evaluates to EmptyValue (a Symbol sentinel, not undefined).
The previous guard  passed EmptyValue through,
bypassing the declared defaultValue and coercing it to 0 or false instead.

Fix: treat EmptyValue as absent only when the parameter declares an explicit
defaultValue, so functions like LOG, VLOOKUP, MATCH etc. get their correct defaults.
@marcin-kordas-hoc
Copy link
Collaborator Author

Wrong origin

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.

1 participant