Fix: ADDRESS function ignores defaultValue when user provides empty value for an optional parameter#1631
Merged
marcin-kordas-hoc merged 4 commits intodevelopfrom Mar 24, 2026
Merged
Conversation
Performance comparison of head (7c6fc7c) vs base (4042b04) |
marcin-kordas-hoc
pushed a commit
that referenced
this pull request
Mar 18, 2026
Use the emptyAsDefault parameter flag from PR #1631 instead of manually checking AstNodeType.EMPTY in the SEQUENCE method body. This removes the coupling between the function logic and AST inspection, letting the framework handle empty→default coercion declaratively. Also restores test/testUtils.ts which was removed during merge. https://claude.ai/code/session_01AXRRWx1KiQCiP8mriuxY7k
…ault flag When a user passes an empty argument to ADDRESS (e.g., =ADDRESS(2,3,,FALSE())), the absNum and a1Style parameters now correctly use their declared defaultValue instead of being coerced to 0/FALSE. Adds an opt-in `emptyAsDefault` flag to FunctionArgument metadata. When set, EmptyValue is treated as if the argument was omitted. Applied only to ADDRESS's absNum and a1Style parameters — all other functions continue to coerce empty args to the zero-value for the type, matching Excel behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
sequba
requested changes
Mar 20, 2026
Contributor
sequba
left a comment
There was a problem hiding this comment.
Good job, solid fix.
Please:
- add a CHANGELOG.md entry describing the fix
- update the documentation (custom-functions guide) to describe the new
emptyAsDefaultconfiguration param
- Rewrite JSDoc to avoid internal EmptyValue term, add comparison table - Add emptyAsDefault entry to argument validation options table Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
f09a219 to
c456e93
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Empty cell references incorrectly treated as omitted arguments
- Replaced the EmptyValue runtime check with a syntacticallyEmptyFlags array derived from AstNodeType.EMPTY, so only truly omitted arguments (not empty cell references) trigger the emptyAsDefault defaultValue substitution.
Or push these changes by commenting:
@cursor push 4bd2d5663a
Preview (4bd2d5663a)
diff --git a/src/interpreter/plugin/FunctionPlugin.ts b/src/interpreter/plugin/FunctionPlugin.ts
--- a/src/interpreter/plugin/FunctionPlugin.ts
+++ b/src/interpreter/plugin/FunctionPlugin.ts
@@ -312,6 +312,29 @@
return ret
}
+ /**
+ * Builds syntactically-empty flags aligned with the expanded evaluated arguments.
+ * When ranges are expanded, a single AST node may produce multiple evaluated values;
+ * only nodes with `AstNodeType.EMPTY` are considered syntactically empty.
+ */
+ private buildSyntacticallyEmptyFlagsForExpandedArgs(args: Ast[], evaluatedArguments: [InterpreterValue, boolean][]): boolean[] {
+ const flags: boolean[] = []
+ let evalIdx = 0
+ for (const ast of args) {
+ const isEmpty = ast.type === AstNodeType.EMPTY
+ if (evalIdx < evaluatedArguments.length && evaluatedArguments[evalIdx][1]) {
+ while (evalIdx < evaluatedArguments.length && evaluatedArguments[evalIdx][1]) {
+ flags.push(isEmpty)
+ evalIdx++
+ }
+ } else {
+ flags.push(isEmpty)
+ evalIdx++
+ }
+ }
+ return flags
+ }
+
protected coerceScalarToNumberOrError = (arg: InternalScalarValue): ExtendedNumber | CellError => this.arithmeticHelper.coerceScalarToNumberOrError(arg)
protected coerceToType(arg: InterpreterValue, coercedType: FunctionArgument, state: InterpreterState): Maybe<InterpreterValue | complex | RawNoErrorScalarValue> {
@@ -410,6 +433,9 @@
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const argumentValues: InterpreterValue[] = evaluatedArguments.map(([value, _]: [InterpreterValue, boolean]) => value as InterpreterValue)
const argumentIgnorableFlags = evaluatedArguments.map(([_, ignorable]) => ignorable)
+ const syntacticallyEmptyFlags = metadata.expandRanges
+ ? this.buildSyntacticallyEmptyFlagsForExpandedArgs(args, evaluatedArguments)
+ : args.map((ast) => ast.type === AstNodeType.EMPTY)
const argumentMetadata = this.buildMetadataForEachArgumentValue(argumentValues.length, metadata)
const isVectorizationOn = state.arraysFlag && !metadata.vectorizationForbidden
@@ -421,13 +447,13 @@
if (resultArrayHeight === 1 && resultArrayWidth === 1) {
const vectorizedArguments = this.vectorizeAndBroadcastArgumentsIfNecessary(isVectorizationOn, argumentValues, argumentMetadata, 0, 0)
- return this.calculateSingleCellOfResultArray(state, vectorizedArguments, argumentMetadata, argumentIgnorableFlags, functionImplementation, metadata.returnNumberType)
+ return this.calculateSingleCellOfResultArray(state, vectorizedArguments, argumentMetadata, argumentIgnorableFlags, syntacticallyEmptyFlags, functionImplementation, metadata.returnNumberType)
}
const resultArray: InternalScalarValue[][] = [ ...Array(resultArrayHeight).keys() ].map(row =>
[ ...Array(resultArrayWidth).keys() ].map(col => {
const vectorizedArguments = this.vectorizeAndBroadcastArgumentsIfNecessary(isVectorizationOn, argumentValues, argumentMetadata, row, col)
- const result = this.calculateSingleCellOfResultArray(state, vectorizedArguments, argumentMetadata, argumentIgnorableFlags, functionImplementation, metadata.returnNumberType)
+ const result = this.calculateSingleCellOfResultArray(state, vectorizedArguments, argumentMetadata, argumentIgnorableFlags, syntacticallyEmptyFlags, functionImplementation, metadata.returnNumberType)
if (result instanceof SimpleRangeValue) {
throw new Error('Function returning array cannot be vectorized.')
@@ -445,10 +471,11 @@
vectorizedArguments: Maybe<InterpreterValue>[],
argumentsMetadata: FunctionArgument[],
argumentIgnorableFlags: boolean[],
+ syntacticallyEmptyFlags: boolean[],
functionImplementation: (...arg: any) => InterpreterValue,
returnNumberType: NumberType | undefined,
): RawInterpreterValue {
- const coercedArguments = this.coerceArgumentsToRequiredTypes(state, vectorizedArguments, argumentsMetadata, argumentIgnorableFlags)
+ const coercedArguments = this.coerceArgumentsToRequiredTypes(state, vectorizedArguments, argumentsMetadata, argumentIgnorableFlags, syntacticallyEmptyFlags)
if (coercedArguments instanceof CellError) {
return coercedArguments
@@ -463,15 +490,17 @@
vectorizedArguments: Maybe<InterpreterValue>[],
argumentsMetadata: FunctionArgument[],
argumentIgnorableFlags: boolean[],
+ syntacticallyEmptyFlags: boolean[] = [],
): CellError | Maybe<InterpreterValue | complex | RawNoErrorScalarValue>[] {
const coercedArguments: Maybe<InterpreterValue | complex | RawNoErrorScalarValue>[] = []
for (let i = 0; i < argumentsMetadata.length; i++) {
const argumentMetadata = argumentsMetadata[i]
const rawArg = vectorizedArguments[i]
+ const isSyntacticallyEmpty = !!syntacticallyEmptyFlags[i]
const argumentValue = rawArg === undefined
? argumentMetadata?.defaultValue
- : (rawArg === EmptyValue && argumentMetadata?.emptyAsDefault && argumentMetadata?.defaultValue !== undefined)
+ : (isSyntacticallyEmpty && argumentMetadata?.emptyAsDefault && argumentMetadata?.defaultValue !== undefined)
? argumentMetadata.defaultValue
: rawArgThis Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
sequba
approved these changes
Mar 24, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1631 +/- ##
========================================
Coverage 97.18% 97.18%
========================================
Files 172 172
Lines 14836 14845 +9
Branches 3258 3264 +6
========================================
+ Hits 14418 14427 +9
Misses 418 418
🚀 New features to boost your workflow:
|
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.


Problem
When a user writes
=ADDRESS(1,1,)or=ADDRESS(1,1,1,), the empty argumentis coerced to
0/falseinstead of using the parameter's declareddefaultValue.Excel 2021 and Google Sheets treat empty args as the zero-value for the type
(
0/FALSE) for all functions except ADDRESS, where emptyabsNumanda1Styleuse their declared defaults (1 andtrue).Fixes #1632
Fix
emptyAsDefaultopt-in flag toFunctionArgumentinterfacecoerceArgumentsToRequiredTypes: whenrawArg === EmptyValueANDemptyAsDefaultis set ANDdefaultValueis declared → substitutedefaultValueemptyAsDefault: trueonly to ADDRESSabsNumanda1StyleparametersTests
Regression tests in
handsontable/hyperformula-tests(branchfix/empty-default-value):absNum, emptya1Style, both emptyoptional-parameters.spec.ts: confirms empty args use zero-value coercion (not defaultValue) whenemptyAsDefaultis not setNote
Medium Risk
Touches core
FunctionPluginargument evaluation/coercion to distinguish syntactically empty arguments, which could subtly affect coercion behavior across many functions if misapplied. Change is gated behind an opt-inemptyAsDefaultflag and only enabled forADDRESSparameters in this PR.Overview
Fixes
ADDRESSso syntactically empty optional arguments (e.g.=ADDRESS(2,3,,FALSE())) use the parameterdefaultValueinstead of being coerced to the type’s zero-value.Adds an opt-in
emptyAsDefaultflag toFunctionArgumentand extendsFunctionPlugin’s argument evaluation pipeline to track whether each argument was syntactically empty, allowing coercion to substitutedefaultValuewhenemptyAsDefaultis enabled. Documentation and changelog are updated to reflect the new option and theADDRESSbehavior fix.Written by Cursor Bugbot for commit 7c6fc7c. This will update automatically on new commits. Configure here.