Skip to content

Commit 9cfb7ea

Browse files
committed
fix: preserve matrix data for range refs in function infix expressions
When a range token (e.g. Ledger!H:H) was the first operand in an infix expression inside a function argument (e.g. IF(Ledger!H:H="TRANSFER",...)), there was no handler for the case where nextToken is an infix operator. The range fell through to parseToken which converted the ArgMatrix to a scalar string via formulaArgToToken, losing all matrix data. This caused formulas like MAX(IF(Sheet!Col:Col="X",ABS(Sheet!Col:Col))) to always return 0 because the column reference was reduced to its first cell value before comparison. Add a condition in evalInfixExp to parse the reference directly and push it to opfdStack when a range token inside a function is followed by an infix operator, preserving the full matrix data for element-wise operations.
1 parent 3e9bc14 commit 9cfb7ea

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

calc.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,20 @@ func (f *File) evalInfixExp(ctx *calcContext, sheet, cell string, tokens []efp.T
10331033
opfdStack.Push(result)
10341034
continue
10351035
}
1036+
if nextToken.TType == efp.TokenTypeOperatorInfix {
1037+
// range is first operand in an infix expression within a
1038+
// function argument - parse reference preserving matrix data
1039+
refTo := f.getDefinedNameRefTo(token.TValue, sheet)
1040+
if refTo != "" {
1041+
token.TValue = refTo
1042+
}
1043+
result, err := f.parseReference(ctx, sheet, token.TValue)
1044+
if err != nil {
1045+
return result, err
1046+
}
1047+
opfdStack.Push(result)
1048+
continue
1049+
}
10361050
if nextToken.TType == efp.TokenTypeArgument || nextToken.TType == efp.TokenTypeFunction {
10371051
// parse reference: reference or range at here
10381052
refTo := f.getDefinedNameRefTo(token.TValue, sheet)

0 commit comments

Comments
 (0)