sc/qa/unit/data/functions/spreadsheet/fods/match.fods |   46 +++++++++++++-----
 sc/source/core/tool/interpr1.cxx                      |    6 +-
 2 files changed, 40 insertions(+), 12 deletions(-)

New commits:
commit 0ce4c1e6898ba83d487f1b225dc9ee0bbc00d9fc
Author:     Winfried Donkers <winfrieddonk...@libreoffice.org>
AuthorDate: Sat Dec 31 15:54:57 2022 +0100
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Thu Jan 12 14:55:30 2023 +0000

    tdf#152774 Fix incorrect result with MATCH.
    
    Use case now complies with ODF 6.9.14 (MATCH).
    Added use case to unit test.
    
    Change-Id: I749a979135fbc01a3bb1583092fb6d6a100e2d2d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144883
    Tested-by: Jenkins
    Reviewed-by: Eike Rathke <er...@redhat.com>

diff --git a/sc/qa/unit/data/functions/spreadsheet/fods/match.fods 
b/sc/qa/unit/data/functions/spreadsheet/fods/match.fods
index a050773c07e3..d5debd0d6339 100644
--- a/sc/qa/unit/data/functions/spreadsheet/fods/match.fods
+++ b/sc/qa/unit/data/functions/spreadsheet/fods/match.fods
@@ -5716,11 +5716,23 @@
      <table:table-cell table:style-name="ce33"/>
      <table:table-cell table:number-columns-repeated="16"/>
     </table:table-row>
-    <table:table-row table:style-name="ro6">
-     <table:table-cell table:style-name="ce13" 
table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce16"/>
-     <table:table-cell table:style-name="ce19"/>
-     <table:table-cell table:number-columns-repeated="3"/>
+    <table:table-row table:style-name="ro2">
+     <table:table-cell table:style-name="ce13" 
table:formula="of:=MATCH(&quot;a&quot;;{1;3;&quot;b&quot;;&quot;d&quot;};1)" 
office:value-type="string" office:string-value="" calcext:value-type="error">
+      <text:p>#N/A</text:p>
+     </table:table-cell>
+     <table:table-cell table:style-name="ce13" table:formula="of:#N/A" 
office:value-type="string" office:string-value="" calcext:value-type="error">
+      <text:p>#N/A</text:p>
+     </table:table-cell>
+     <table:table-cell table:style-name="ce48" 
table:formula="of:=ISERROR([.A118])" office:value-type="boolean" 
office:boolean-value="true" calcext:value-type="boolean">
+      <text:p>TRUE</text:p>
+     </table:table-cell>
+     <table:table-cell table:formula="of:=FORMULA([.A118])" 
office:value-type="string" 
office:string-value="=MATCH(&quot;a&quot;,{1,3,&quot;b&quot;,&quot;d&quot;},1)" 
calcext:value-type="string">
+      
<text:p>=MATCH(&quot;a&quot;,{1,3,&quot;b&quot;,&quot;d&quot;},1)</text:p>
+     </table:table-cell>
+     <table:table-cell office:value-type="string" calcext:value-type="string">
+      <text:p>Tdf#152774</text:p>
+     </table:table-cell>
+     <table:table-cell table:number-columns-repeated="2"/>
      <table:table-cell office:value-type="float" office:value="4" 
calcext:value-type="float">
       <text:p>4</text:p>
      </table:table-cell>
@@ -5731,11 +5743,23 @@
      <table:table-cell table:style-name="ce33"/>
      <table:table-cell table:number-columns-repeated="16"/>
     </table:table-row>
-    <table:table-row table:style-name="ro6">
-     <table:table-cell table:style-name="ce13" 
table:number-columns-repeated="2"/>
-     <table:table-cell table:style-name="ce16"/>
-     <table:table-cell table:style-name="ce19"/>
-     <table:table-cell table:number-columns-repeated="3"/>
+    <table:table-row table:style-name="ro2">
+     <table:table-cell table:style-name="ce13" 
table:formula="of:=MATCH(4;{&quot;d&quot;;&quot;b&quot;;3;1};-1)" 
office:value-type="string" office:string-value="" calcext:value-type="error">
+      <text:p>#N/A</text:p>
+     </table:table-cell>
+     <table:table-cell table:style-name="ce13" table:formula="of:#N/A" 
office:value-type="string" office:string-value="" calcext:value-type="error">
+      <text:p>#N/A</text:p>
+     </table:table-cell>
+     <table:table-cell table:style-name="ce49" 
table:formula="of:=ISERROR([.A119])" office:value-type="boolean" 
office:boolean-value="true" calcext:value-type="boolean">
+      <text:p>TRUE</text:p>
+     </table:table-cell>
+     <table:table-cell table:formula="of:=FORMULA([.A119])" 
office:value-type="string" 
office:string-value="=MATCH(4,{&quot;d&quot;,&quot;b&quot;,3,1},-1)" 
calcext:value-type="string">
+      <text:p>=MATCH(4,{&quot;d&quot;,&quot;b&quot;,3,1},-1)</text:p>
+     </table:table-cell>
+     <table:table-cell office:value-type="string" calcext:value-type="string">
+      <text:p>Tdf#152774</text:p>
+     </table:table-cell>
+     <table:table-cell table:number-columns-repeated="2"/>
      <table:table-cell office:value-type="float" office:value="3" 
calcext:value-type="float">
       <text:p>3</text:p>
      </table:table-cell>
@@ -6255,4 +6279,4 @@
    </table:named-expressions>
   </office:spreadsheet>
  </office:body>
-</office:document>
\ No newline at end of file
+</office:document>
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 0785318da871..c47aec4b052c 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -5052,7 +5052,11 @@ void ScInterpreter::ScMatch()
 
             if (nHitIndex > 0) // valid hit must be 2nd item or higher
             {
-                PushDouble( nHitIndex); // non-exact match
+                if ( ! ( rItem.meType == ScQueryEntry::ByString &&  
aMatAcc.IsValue( nHitIndex-1 ) ) &&
+                     ! ( rItem.meType == ScQueryEntry::ByValue  && 
!aMatAcc.IsValue( nHitIndex-1 ) ) )
+                    PushDouble( nHitIndex); // non-exact match
+                else
+                    PushNA();
                 return;
             }
 

Reply via email to