summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--formula/source/core/api/FormulaCompiler.cxx27
-rw-r--r--sc/source/core/tool/interpr4.cxx4
2 files changed, 26 insertions, 5 deletions
diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index 6859e744ca15..db32c1de0ff1 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -1401,18 +1401,37 @@ void FormulaCompiler::Factor()
NextToken();
CheckSetForceArrayParameter( mpToken, 0);
eOp = Expression();
- // Do not ignore error here, regardless of bIgnoreErrors, otherwise
- // errors like =(1;) would also result in display of =(1~)
+ // Do not ignore error here, regardless of mbStopOnError, to not
+ // change the formula expression in case of an unexpected state.
if (pArr->GetCodeError() == FormulaError::NONE)
{
- pFacToken->NewOpCode( ocUnion, FormulaToken::PrivateAccess());
- PutCode( pFacToken);
+ // Left and right operands must be reference or function
+ // returning reference to form a range list.
+ const FormulaToken* p;
+ if (pc >= 2
+ && ((p = pCode[-2]) != nullptr) && isPotentialRangeType( p, true, false)
+ && ((p = pCode[-1]) != nullptr) && isPotentialRangeType( p, true, true))
+ {
+ pFacToken->NewOpCode( ocUnion, FormulaToken::PrivateAccess());
+ PutCode( pFacToken);
+ }
}
}
if (eOp != ocClose)
SetError( FormulaError::PairExpected);
else
NextToken();
+
+ /* TODO: if no conversion to ocUnion is involved this could collect
+ * such expression as a list or (matrix) vector to be passed as
+ * argument for one parameter (which in fact the ocUnion svRefList is a
+ * special case of), which would require a new StackVar type and needed
+ * to be handled by the interpreter for functions that could support it
+ * (i.e. already handle VAR_ARGS or svRefList parameters). This is also
+ * not defined by ODF.
+ * Does Excel handle =SUM((1;2))?
+ * As is, the interpreter catches extraneous uncalculated
+ * subexpressions like 1 of (1;2) as error. */
}
else
{
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 4b5ff2281bfa..c47b33f8488c 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -4507,7 +4507,7 @@ StackVar ScInterpreter::Interpret()
bForcedResultType = false;
}
- if( sp )
+ if (sp == 1)
{
pCur = pStack[ sp-1 ];
if( pCur->GetOpCode() == ocPush )
@@ -4634,6 +4634,8 @@ StackVar ScInterpreter::Interpret()
else
SetError( FormulaError::UnknownStackVariable);
}
+ else if (sp > 1)
+ SetError( FormulaError::OperatorExpected);
else
SetError( FormulaError::NoCode);