Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2fa0930
Fix HF-361: empty string no longer coerces to 0
marcin-kordas-hoc Sep 10, 2026
78b1c75
HF-361: complete the Definition of Done for the empty-string change
marcin-kordas-hoc Sep 10, 2026
c99427b
HF-361: correct the scope of the change in the changelog and migratio…
marcin-kordas-hoc Sep 10, 2026
a24a523
HF-361: look through parentheses when checking for a reference in num…
marcin-kordas-hoc Sep 22, 2026
23fb194
docs: shorten the changelog entry to one sentence
marcin-kordas-hoc Oct 22, 2026
159f352
Merge develop into fix/hf-361-empty-string-coercion
marcin-kordas-hoc Oct 22, 2026
731a20f
HF-361: Describe the parenthesized-reference change in the changelog …
marcin-kordas-hoc Oct 23, 2026
761251f
HF-361: Write TRUE() in the migration guide's IF examples, which Hype…
marcin-kordas-hoc Oct 23, 2026
cc66c2a
HF-361: Keep only Excel values that were measured in the migration guide
marcin-kordas-hoc Oct 23, 2026
40d669e
Merge develop into fix/hf-361-empty-string-coercion
marcin-kordas-hoc Oct 30, 2026
4c96a66
List the text-only array argument among the differences from Excel
marcin-kordas-hoc Oct 30, 2026
8bc9db8
HF-361: Ship the empty-string change as a fix: move the entry to Fixe…
marcin-kordas-hoc Nov 3, 2026
d476660
HF-361: Say in the types-of-values guide that an empty string is Text…
marcin-kordas-hoc Nov 3, 2026
8b624ed
Merge branch 'develop' into fix/hf-361-empty-string-coercion
marcin-kordas-hoc Nov 3, 2026
299f1b2
Merge branch 'develop' into fix/hf-361-empty-string-coercion
marcin-kordas-hoc Nov 3, 2026
c3e9ff8
Merge branch 'develop' into fix/hf-361-empty-string-coercion
marcin-kordas-hoc Nov 4, 2026
42b44ec
Merge branch 'develop' into fix/hf-361-empty-string-coercion
marcin-kordas-hoc Nov 12, 2026
fe2b028
HF-361: State what coerceNonDateScalarToMaybeNumber returns for a bla…
marcin-kordas-hoc Nov 12, 2026
3219161
HF-361: List text returned by INDEX, CHOOSE, IF or a name among the d…
marcin-kordas-hoc Nov 12, 2026
19eeb5b
HF-361: Ignore text read through INDEX, CHOOSE, IF or a name in aggre…
marcin-kordas-hoc Nov 15, 2026
05f0a52
HF-361: Order the Unreleased changelog sections as Keep a Changelog does
marcin-kordas-hoc Nov 15, 2026
2061f15
HF-361: Check the built-in plugin only for INDEX, IF and CHOOSE argum…
marcin-kordas-hoc Nov 15, 2026
7afdb57
HF-361: Read IF and CHOOSE by the argument they returned in aggregations
marcin-kordas-hoc Nov 16, 2026
afb1cfb
HF-361: Read IFS and SWITCH by the argument they returned in aggregat…
marcin-kordas-hoc Nov 16, 2026
4c7d42f
Merge branch 'develop' into fix/hf-361-empty-string-coercion
marcin-kordas-hoc Nov 18, 2026
aff4073
Merge branch 'develop' into fix/hf-361-empty-string-coercion
marcin-kordas-hoc Nov 18, 2026
4618450
Merge remote-tracking branch 'origin/develop' into fix/hf-361-empty-s…
marcin-kordas-hoc Nov 19, 2026
0dcb986
Read XLOOKUP results and IF or CHOOSE ranges as references in numeric…
marcin-kordas-hoc Nov 19, 2026
6af2f10
Merge branch 'develop' into fix/hf-361-empty-string-coercion
marcin-kordas-hoc Nov 19, 2026
2f86335
Merge branch 'develop' into fix/hf-361-empty-string-coercion
marcin-kordas-hoc Nov 19, 2026
c4c3ad8
Remove the RANK.EQ empty-string rows from the list of differences
marcin-kordas-hoc Nov 19, 2026
4ded7b8
Merge branch 'develop' into fix/hf-361-empty-string-coercion
marcin-kordas-hoc Nov 19, 2026
f494586
Merge branch 'develop' into fix/hf-361-empty-string-coercion
Tobiadefami Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fixed functions such as `MATCH`, `INDEX` and `COUNTIF` throwing an uncaught `Unknown array` error when they read a range that exactly matches the area of an array formula returning an error, for example `=MATCH(2, B1:B3, 0)` next to `=SORT(A1:A3)` whose source contains `#DIV/0!`. They now read the range cell by cell. [#1876](https://github.com/handsontable/hyperformula/pull/1876)
- Fixed unbounded parser cache growth in long-running instances that process many distinct formulas, including when undo is disabled. [#1635](https://github.com/handsontable/hyperformula/issues/1635)
- Fixed array formulas spilling past the `maxRows` and `maxColumns` limits: they now return `#SPILL!` when their result extends beyond the sheet edge. [#1774](https://github.com/handsontable/hyperformula/pull/1774)
- Fixed numeric contexts reading an empty string (`""`) as `0` instead of as text (e.g. `=""+0` now returns `#VALUE!` instead of `0`), and numeric aggregations treating a parenthesized reference such as `(A1)` differently from `A1`. [#1768](https://github.com/handsontable/hyperformula/pull/1768)
- Fixed numeric aggregations such as `SUM`, `AVERAGE` and `MAX` reading a cell reached through `INDEX`, `CHOOSE`, `IF`, `IFS`, `SWITCH` or a named expression as a value: as with a direct reference, its text, booleans and blanks are now ignored. [#1768](https://github.com/handsontable/hyperformula/pull/1768)
- Fixed the `ADDRESS` function adding the sheet separator (`!`) when the `sheetName` argument is an empty argument slot (e.g. `=ADDRESS(2,3,1,FALSE(),)` now returns `R2C3` instead of `!R2C3`), while an explicit `""` still adds it. [#1641](https://github.com/handsontable/hyperformula/issues/1641)

## [3.5.0] - 2026-10-09
Expand Down
1 change: 1 addition & 0 deletions docs/guide/list-of-differences.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Very large or very small input scales can also cause substantial differences in
| Booleans converted to text | =CONCAT(TRUE())<br><br>=VALUETOTEXT(FALSE())<br><br>=TRUE()&"" | `TRUE` and `FALSE` in every language, in `CONCAT`, `CONCATENATE`, `TEXTJOIN`, `VALUETOTEXT` and `&`. | Not checked. | The boolean names of the Excel language, for example `PRAWDA` and `FAŁSZ` in Polish. |
| Array size limits | =SUM(VSTACK(SEQUENCE(1048576), SEQUENCE(1))) | An array computed inside a formula is not limited in either dimension, so the example returns the sum when [`maxRows`](../api/interfaces/configparams.md#maxrows) is at least 1,048,576. With the default `maxRows` (40,000), `SEQUENCE(1048576)` returns `#VALUE!`, because `SEQUENCE` is limited by the `maxRows` and [`maxColumns`](../api/interfaces/configparams.md#maxcolumns) configuration options. | In-memory arrays are not limited in either dimension. Returns `549756338177`. | In-memory arrays are limited to 1,048,576 rows and 1,048,576 columns. Returns `#NUM!`. |
| FILTER and UNIQUE near the sheet edge | =FILTER(A1:A10, A1:A10>8)<br>in the second-to-last row, where A1:A10 = 1 to 10 | Returns `#SPILL!`: the area reserved for the result has the height of the source, and it does not fit before the sheet edge. See [Known limitations](known-limitations.md). | Not checked. | Spills `9` and `10` into the last two rows. |
| Text-only array argument in numeric aggregations | B1: =SUM(IF(A1:A3>0,"",A1:A3))<br>where A1:A3 = 1, 2, 3<br><br>=COUNT(IF({1,0},"",5)) | With the [array arithmetic mode](arrays.md#array-arithmetic-mode) disabled (the default), `IF` returns a single value, here the empty string, which is text: `SUM` returns `#VALUE!` and `COUNT` returns `0`. With the mode enabled, `IF` returns an array, and the results are `0` and `1`. | Not checked. | `IF` returns an array, and the aggregations ignore the text in it: `SUM` returns `0` and `COUNT` returns `1`. |
| TYPE of ROW or COLUMN in an expression | =TYPE(ROW(A1:A2)+0) | `ROW` over more than one row and `COLUMN` over more than one column count as arrays only when passed to `TYPE` directly, so the example gives `1`. | Not checked. | Returns `64`. |
| TYPE of a one-by-one array | =TYPE({1}+0)<br>=TYPE(IF(TRUE(), {1}))<br>=TYPE(VSTACK(A1))<br>where A1 holds an error | An array that holds a single value counts as an array (`64`) only when it is the argument itself: an array constant, a call to a function that returns arrays, such as `FILTER`, `SEQUENCE` or `VSTACK`, or `TRANSPOSE` of such an array. Passed through an operator or another function first, it is reduced to its value, so the first two examples give `1`. When such a function call has an error as its single value, `TYPE` gives `16`, as in the third example. | Not checked. | Returns `64` for all three examples. |
| ERROR.TYPE function | =ERROR.TYPE(#NULL!)<br>=ERROR.TYPE(#GETTING_DATA) | HyperFormula has no `#NULL!` or `#GETTING_DATA` error, so the codes 1 and 8 are never returned and the literals do not parse. `#CYCLE!`, `#ERROR!` and `#LIC!`, which are HyperFormula's own errors, have no code and give `#N/A`. | Not checked. | Returns `1` for `#NULL!` and `8` for `#GETTING_DATA`. |
Expand Down
2 changes: 2 additions & 0 deletions docs/guide/types-of-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ When you pass JavaScript values directly (not as strings):
- `Date` object → **Date/DateTime type** (converted to internal numeric representation)
- `null` or `undefined` → **Empty cell**

To empty a cell, pass `null`, not an empty string: `''` is stored as Text, so `=A1+1` returns `#VALUE!` when `A1` holds it.

```js
const hf = HyperFormula.buildFromArray([
[42], // Number
Expand Down
11 changes: 7 additions & 4 deletions hyperformula/src/interpreter/ArithmeticHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,17 @@ export class ArithmeticHelper {
)
}

/**
* Coerces a scalar value to a number for use in arithmetic and numeric aggregation, without
* attempting date-string parsing (see {@link coerceToMaybeNumber} for that extra step).
*
* A blank cell (`EmptyValue`) reads as `0`. An empty string is text, so like any non-numeric
* string it returns `undefined`.
*/
public coerceNonDateScalarToMaybeNumber(arg: InternalScalarValue): Maybe<ExtendedNumber> {
if (arg === EmptyValue) {
return 0
Comment thread
marcin-kordas-hoc marked this conversation as resolved.
Resolved
} else if (typeof arg === 'string') {
if (arg === '') {
return 0
}

const maybePercentNumber = this.coerceStringToMaybePercentNumber(arg)
if (maybePercentNumber !== undefined) {
return maybePercentNumber
Expand Down
74 changes: 69 additions & 5 deletions hyperformula/src/interpreter/plugin/BooleanPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,33 @@

import {CellError, ErrorType} from '../../Cell'
import {ErrorMessage} from '../../error-message'
import {ProcedureAst} from '../../parser'
import {Maybe} from '../../Maybe'
import {Ast, ProcedureAst} from '../../parser'
import {InterpreterState} from '../InterpreterState'
import {InternalNoErrorScalarValue, InternalScalarValue, InterpreterValue} from '../InterpreterValue'
import {SimpleRangeValue} from '../../SimpleRangeValue'
import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck, ImplementedFunctions} from './FunctionPlugin'

/**
* For a call to `IF`, `IFS`, `SWITCH` or `CHOOSE`, the argument that its last evaluation returned. A call
* that returned none of its arguments, such as one whose selector is an error or out of range, one where
* no condition or case matched, one that returned the default value of an omitted argument, or one that
* returned an array, has no entry.
*/
const selectedArguments = new WeakMap<ProcedureAst, Ast>()

/**
* Returns the argument that the call to `IF`, `IFS`, `SWITCH` or `CHOOSE` returned when it was last
* evaluated, so that a function that has just evaluated the call can tell whether its result is the
* content of a referenced cell.
*
* @param {ProcedureAst} ast - a call to `IF`, `IFS`, `SWITCH` or `CHOOSE` evaluated by this plugin
* @returns {Maybe<Ast>} the returned argument, or `undefined` when the call returned none of its arguments
*/
export function selectedArgument(ast: ProcedureAst): Maybe<Ast> {
return selectedArguments.get(ast)
}

/**
* Interpreter plugin containing boolean functions
*/
Expand Down Expand Up @@ -135,9 +157,12 @@ export class BooleanPlugin extends FunctionPlugin implements FunctionPluginTypec
* @param state
*/
public conditionalIf(ast: ProcedureAst, state: InterpreterState): InterpreterValue {
return this.runFunction(ast.args, state, this.metadata('IF'), (condition, arg2, arg3) => {
selectedArguments.delete(ast)
const result = this.runFunction(ast.args, state, this.metadata('IF'), (condition, arg2, arg3) => {
recordSelectedArgument(ast, condition ? 1 : 2)
return condition ? arg2 : arg3
})
return forgetSelectionUnlessScalar(ast, result)
}

/**
Expand All @@ -147,14 +172,17 @@ export class BooleanPlugin extends FunctionPlugin implements FunctionPluginTypec
* @param state
*/
public ifs(ast: ProcedureAst, state: InterpreterState): InterpreterValue {
return this.runFunction(ast.args, state, this.metadata('IFS'), (...args) => {
selectedArguments.delete(ast)
const result = this.runFunction(ast.args, state, this.metadata('IFS'), (...args) => {
for (let idx = 0; idx < args.length; idx += 2) {
if (args[idx]) {
recordSelectedArgument(ast, idx + 1)
return args[idx+1]
}
}
return new CellError(ErrorType.NA, ErrorMessage.NoConditionMet)
})
return forgetSelectionUnlessScalar(ast, result)
}

/**
Expand Down Expand Up @@ -202,23 +230,27 @@ export class BooleanPlugin extends FunctionPlugin implements FunctionPluginTypec
}

public switch(ast: ProcedureAst, state: InterpreterState): InterpreterValue {
return this.runFunction(ast.args, state, this.metadata('SWITCH'), (selector, ...args) => {
selectedArguments.delete(ast)
const result = this.runFunction(ast.args, state, this.metadata('SWITCH'), (selector, ...args) => {
const n = args.length
let i = 0
for (; i + 1 < n; i += 2) {
if (args[i] instanceof CellError) {
continue
}
if (this.arithmeticHelper.eq(selector, args[i] as InternalNoErrorScalarValue)) {
recordSelectedArgument(ast, i + 2)
return args[i + 1]
}
}
if (i < n) {
recordSelectedArgument(ast, i + 1)
return args[i]
} else {
return new CellError(ErrorType.NA, ErrorMessage.NoDefault)
}
})
return forgetSelectionUnlessScalar(ast, result)
}

public iferror(ast: ProcedureAst, state: InterpreterState): InterpreterValue {
Expand All @@ -242,11 +274,43 @@ export class BooleanPlugin extends FunctionPlugin implements FunctionPluginTypec
}

public choose(ast: ProcedureAst, state: InterpreterState): InterpreterValue {
return this.runFunction(ast.args, state, this.metadata('CHOOSE'), (selector, ...args) => {
selectedArguments.delete(ast)
const result = this.runFunction(ast.args, state, this.metadata('CHOOSE'), (selector: number, ...args) => {
if (selector > args.length) {
return new CellError(ErrorType.NUM, ErrorMessage.Selector)
}
recordSelectedArgument(ast, selector)
return args[selector - 1]
})
return forgetSelectionUnlessScalar(ast, result)
}
}

/**
* Records that a call to `IF`, `IFS`, `SWITCH` or `CHOOSE` returned its argument at the given position.
*
* @param {ProcedureAst} ast - the call
* @param {number} position - the position of the returned argument in `ast.args`
*/
function recordSelectedArgument(ast: ProcedureAst, position: number): void {
const argument = ast.args[position]
if (argument === undefined) {
selectedArguments.delete(ast)
} else {
selectedArguments.set(ast, argument)
}
}

/**
* Removes the record of a call that returned an array, where each cell can come from a different argument.
*
* @param {ProcedureAst} ast - the call
* @param {InterpreterValue} result - what the call returned
* @returns {InterpreterValue} `result`, unchanged
*/
function forgetSelectionUnlessScalar(ast: ProcedureAst, result: InterpreterValue): InterpreterValue {
if (result instanceof SimpleRangeValue) {
selectedArguments.delete(ast)
}
return result
}
Comment thread
Tobiadefami marked this conversation as resolved.
Resolved
115 changes: 113 additions & 2 deletions hyperformula/src/interpreter/plugin/NumericAggregationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ import {EmptyValue, ExtendedNumber, getRawValue, InternalScalarValue, isExtended
import {SimpleRangeValue} from '../../SimpleRangeValue'
import {AverageResult} from './AverageResult'
import {MomentsAggregate} from './MomentsAggregate'
import {FunctionArgumentType, FunctionPlugin, FunctionPluginTypecheck, ImplementedFunctions} from './FunctionPlugin'
import {FunctionArgumentType, FunctionPlugin, FunctionPluginDefinition, FunctionPluginTypecheck, ImplementedFunctions} from './FunctionPlugin'
import {RangeVertex} from '../../DependencyGraph'
import {FormulaVertex} from '../../DependencyGraph/FormulaVertex'
import {BooleanPlugin, selectedArgument} from './BooleanPlugin'
import {InformationPlugin} from './InformationPlugin'

export type BinaryOperation<T> = (left: T, right: T) => T

Expand Down Expand Up @@ -517,6 +520,12 @@ export class NumericAggregationPlugin extends FunctionPlugin implements Function
return acc
}

// A parenthesized argument such as `(A1)` arrives as a PARENTHESIS node wrapping the reference.
// Unwrap it so that the checks below see the reference and ignore its non-numeric values.
while (arg.type === AstNodeType.PARENTHESIS) {
arg = arg.expression
}
Comment thread
marcin-kordas-hoc marked this conversation as resolved.
Resolved

if (arg.type === AstNodeType.CELL_RANGE || arg.type === AstNodeType.COLUMN_RANGE || arg.type === AstNodeType.ROW_RANGE) {
const val = this.evaluateRange(arg, state, initialAccValue, functionName, reducingFunction, mapFunction, coercionFunction)
if (val instanceof CellError) {
Expand Down Expand Up @@ -549,7 +558,7 @@ export class NumericAggregationPlugin extends FunctionPlugin implements Function
return reducingFunction(left, right)
}
}, acc)
} else if (arg.type === AstNodeType.CELL_REFERENCE) {
} else if (arg.type === AstNodeType.CELL_REFERENCE || this.evaluatesToReference(arg, state)) {
value = coercionFunction(value)
if (value === undefined) {
return acc
Expand All @@ -570,6 +579,108 @@ export class NumericAggregationPlugin extends FunctionPlugin implements Function
}, initialAccValue)
}

/**
* Tells whether an argument other than a bare reference or range, which has just been evaluated,
* returned the content of a referenced cell, so that the aggregation ignores its non-numeric values
* as it does for `A1`.
*
* That holds for a parenthesized reference, a named expression defined as a reference, `INDEX`
* over a reference, and `IF`, `IFS`, `SWITCH` or `CHOOSE` whose evaluation returned one of these.
* These four report the argument they returned, so no argument is evaluated a second time. `IFERROR`
* and `IFNA` are not among them: they return the value of the cell, as in Excel. `INDEX`, `IF`, `IFS`,
* `SWITCH` and `CHOOSE` count only while the built-in implementation answers for them, not a custom
* plugin registered over their ids.
*
* @param {Ast} arg - the argument of the aggregation, already evaluated
* @param {InterpreterState} state - interpreter state
* @returns {boolean} whether the value of `arg` is the content of a referenced cell
*/
private evaluatesToReference(arg: Ast, state: InterpreterState): boolean {
switch (arg.type) {
case AstNodeType.PARENTHESIS:
return this.evaluatesToReference(arg.expression, state)
case AstNodeType.CELL_REFERENCE:
case AstNodeType.CELL_RANGE:
case AstNodeType.COLUMN_RANGE:
case AstNodeType.ROW_RANGE:
return true
case AstNodeType.NAMED_EXPRESSION:
return this.namedExpressionIsReference(arg.expressionName, state)
case AstNodeType.FUNCTION_CALL:
return this.functionCallEvaluatesToReference(arg, state)
default:
return false
}
}

/**
* The function-call case of {@link evaluatesToReference}: `INDEX` over a reference, and `IF`, `IFS`,
* `SWITCH` or `CHOOSE` that returned a reference.
*
* @param {ProcedureAst} ast - the function call passed to the aggregation, already evaluated
* @param {InterpreterState} state - interpreter state
* @returns {boolean} whether the function call returned the content of a referenced cell
*/
private functionCallEvaluatesToReference(ast: ProcedureAst, state: InterpreterState): boolean {
switch (ast.procedureName) {
case 'INDEX':
return this.isBuiltIn('INDEX', InformationPlugin)
&& ast.args.length >= 1
&& this.evaluatesToReference(ast.args[0], state)
case 'IF':
case 'IFS':
case 'SWITCH':
case 'CHOOSE': {
if (!this.isBuiltIn(ast.procedureName, BooleanPlugin)) {
return false
}
const returnedArgument = selectedArgument(ast)
return returnedArgument !== undefined && this.evaluatesToReference(returnedArgument, state)
}
default:
return false
}
}
Comment thread
Tobiadefami marked this conversation as resolved.
Resolved

/**
* Tells whether the built-in plugin answers for a function id, rather than a custom plugin
* registered over it.
*
* @param {string} functionId - the function id
* @param {FunctionPluginDefinition} builtInPlugin - the plugin that implements the id by default
* @returns {boolean} whether `builtInPlugin` is registered for `functionId`
*/
private isBuiltIn(functionId: string, builtInPlugin: FunctionPluginDefinition): boolean {
return this.dependencyGraph.functionRegistry.getFunctionPlugin(functionId) === builtInPlugin
}

/**
* Tells whether a named expression, as seen from the formula being evaluated, is defined as a
* reference or a range, optionally in parentheses. Other definitions, such as `=""`, are values.
*
* @param {string} expressionName - the name used in the formula
* @param {InterpreterState} state - interpreter state
* @returns {boolean} whether the named expression is a reference
*/
private namedExpressionIsReference(expressionName: string, state: InterpreterState): boolean {
const namedExpression = this.dependencyGraph.namedExpressions.nearestNamedExpression(expressionName, state.formulaAddress.sheet)
if (namedExpression === undefined) {
return false
}
const vertex = this.dependencyGraph.getCell(namedExpression.address)
if (!(vertex instanceof FormulaVertex)) {
return false
}
let definition = vertex.getFormula(this.dependencyGraph.lazilyTransformingAstService)
while (definition.type === AstNodeType.PARENTHESIS) {
definition = definition.expression
}
return definition.type === AstNodeType.CELL_REFERENCE
|| definition.type === AstNodeType.CELL_RANGE
|| definition.type === AstNodeType.COLUMN_RANGE
|| definition.type === AstNodeType.ROW_RANGE
}

/**
* Performs range operation on given range
*
Expand Down
Loading