diff options
author | Balazs Varga <balazs.varga.extern@allotropia.de> | 2024-04-10 17:48:20 +0100 |
---|---|---|
committer | Thorsten Behrens <thorsten.behrens@allotropia.de> | 2024-04-30 15:10:44 +0200 |
commit | e9208a9d03a6e06e80a6cc9335d9886c90d776f2 (patch) | |
tree | 02514921bbf9d5ba341dfa159cb6720d30b499a8 | |
parent | clean up after removal of patched rhino (diff) | |
download | core-e9208a9d03a6e06e80a6cc9335d9886c90d776f2.tar.gz core-e9208a9d03a6e06e80a6cc9335d9886c90d776f2.zip |
tdf#160616 - Fix SUMPRODUCT calculation is broken in some cases
Double refs with operators only trimmable in case of one root paramater.
Follow up of: ba0ec4a5d2b025b675410cd18890d1cca3bc5a2f
Change-Id: If61fb39696d9539ffc9d32a6ecad79bfa1bf92e5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165957
Tested-by: Gabor Kelemen <gabor.kelemen.extern@allotropia.de>
Tested-by: Jenkins
Reviewed-by: Gabor Kelemen <gabor.kelemen.extern@allotropia.de>
(cherry picked from commit 2af433f11cf24db655677bdf26e39fabaf3611fc)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165932
Tested-by: allotropia jenkins <jenkins@allotropia.de>
Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
-rw-r--r-- | sc/qa/unit/ucalc_formula.cxx | 2 | ||||
-rw-r--r-- | sc/source/core/tool/compiler.cxx | 9 |
2 files changed, 8 insertions, 3 deletions
diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index 153096d6a434..feb0e8fef22a 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -1464,7 +1464,7 @@ CPPUNIT_TEST_FIXTURE(TestFormula, testFormulaAnnotateTrimOnDoubleRefs) { "=SUMPRODUCT(A:A=$C$1; 1-(A:A=$C$1))", - ScRange(0, 0, 0, 0, 1048575, 0), + ScRange(-1, -1, -1, -1, -1, -1), // Has no trimmable double-ref. 0.0, false // Not in matrix mode. }, diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index 451956922c29..7e1fa777bfec 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -6477,6 +6477,8 @@ void ScCompiler::AnnotateTrimOnDoubleRefs() // OpCode of the "root" operator (which is already in RPN array). OpCode eOpCode = (*(pCode - 1))->GetOpCode(); + // Param number of the "root" operator (which is already in RPN array). + sal_uInt8 nRootParam = (*(pCode - 1))->GetByte(); // eOpCode can be some operator which does not change with operands with or contains zero values. if (eOpCode == ocSum) { @@ -6569,7 +6571,8 @@ void ScCompiler::AnnotateTrimOnDoubleRefs() // such that one of the operands of ocEqual is a double-ref. // Examples of formula that matches this are: // SUMPRODUCT(IF($A:$A=$L12;$D:$D*G:G)) - // Also in case of DoubleRef arguments around other Binary operators can be trimmable: + // Also in case of DoubleRef arguments around other Binary operators can be trimmable inside one parameter + // of the root operator: // SUMPRODUCT(($D:$D>M47:M47)*($D:$D<M48:M48)*($I:$I=N$41)) bool bTillClose = true; bool bCloseTillIf = false; @@ -6621,7 +6624,9 @@ void ScCompiler::AnnotateTrimOnDoubleRefs() case ocUnion: case ocRange: { - if (!pTok->IsInForceArray()) + // tdf#160616: Double refs with these operators only + // trimmable in case of one paramater + if (!pTok->IsInForceArray() || nRootParam > 1) break; FormulaToken* pLHS = *(ppTok - 1); FormulaToken* pRHS = *(ppTok - 2); |