Index: src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Match.java =================================================================== --- src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Match.java (revision 627801) +++ src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/Match.java (working copy) @@ -26,7 +26,6 @@ import org.apache.poi.hssf.record.formula.eval.RefEval; import org.apache.poi.hssf.record.formula.eval.StringEval; import org.apache.poi.hssf.record.formula.eval.ValueEval; -import org.apache.poi.hssf.util.AreaReference; /** * Implementation for the MATCH() Excel function.

@@ -188,7 +187,7 @@ private static double evaluateMatchTypeArg(Eval arg, int srcCellRow, short srcCellCol) throws EvalEx { Eval match_type = arg; - if(arg instanceof AreaReference) { + if(arg instanceof AreaEval) { AreaEval ae = (AreaEval) arg; // an area ref can work as a scalar value if it is 1x1 if(ae.isColumn() && ae.isRow()) { Index: src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestMatch.java =================================================================== --- src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestMatch.java (revision 627801) +++ src/scratchpad/testcases/org/apache/poi/hssf/record/formula/functions/TestMatch.java (working copy) @@ -21,6 +21,7 @@ import org.apache.poi.hssf.record.formula.AreaPtg; import org.apache.poi.hssf.record.formula.eval.Area2DEval; +import org.apache.poi.hssf.record.formula.eval.AreaEval; import org.apache.poi.hssf.record.formula.eval.BoolEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.Eval; @@ -53,6 +54,13 @@ NumericValueEval nve = (NumericValueEval)actualEval; assertEquals(expected, nve.getNumberValue(), 0); } + /** + * Convenience method + * @return new Area2DEval(new AreaPtg(ref), values) + */ + private static AreaEval createAreaEval(String ref, ValueEval[] values) { + return new Area2DEval(new AreaPtg(ref), values); + } public void testSimpleNumber() { @@ -64,10 +72,8 @@ new NumberEval(25), }; - AreaPtg areaPtg = new AreaPtg("A1:A5"); - Area2DEval ae = new Area2DEval(areaPtg, values); + AreaEval ae = createAreaEval("A1:A5", values); - confirmInt(2, invokeMatch(new NumberEval(5), ae, MATCH_LARGEST_LTE)); confirmInt(2, invokeMatch(new NumberEval(5), ae, MATCH_EXACT)); confirmInt(4, invokeMatch(new NumberEval(10), ae, MATCH_LARGEST_LTE)); @@ -86,10 +92,8 @@ new NumberEval(4), }; - AreaPtg areaPtg = new AreaPtg("A1:A5"); - Area2DEval ae = new Area2DEval(areaPtg, values); + AreaEval ae = createAreaEval("A1:A5", values); - confirmInt(2, invokeMatch(new NumberEval(10), ae, MATCH_SMALLEST_GTE)); confirmInt(2, invokeMatch(new NumberEval(10), ae, MATCH_EXACT)); confirmInt(4, invokeMatch(new NumberEval(9), ae, MATCH_SMALLEST_GTE)); @@ -108,8 +112,7 @@ new StringEval("Ian"), }; - AreaPtg areaPtg = new AreaPtg("A1:A5"); - Area2DEval ae = new Area2DEval(areaPtg, values); + AreaEval ae = createAreaEval("A1:A5", values); // Note String comparisons are case insensitive confirmInt(3, invokeMatch(new StringEval("Ed"), ae, MATCH_LARGEST_LTE)); @@ -129,8 +132,7 @@ BoolEval.TRUE, }; - AreaPtg areaPtg = new AreaPtg("A1:A4"); - Area2DEval ae = new Area2DEval(areaPtg, values); + AreaEval ae = createAreaEval("A1:A4", values); // Note String comparisons are case insensitive confirmInt(2, invokeMatch(BoolEval.FALSE, ae, MATCH_LARGEST_LTE)); @@ -157,8 +159,7 @@ new StringEval("Ed"), }; - AreaPtg areaPtg = new AreaPtg("A1:A13"); - Area2DEval ae = new Area2DEval(areaPtg, values); + AreaEval ae = createAreaEval("A1:A13", values); assertEquals(ErrorEval.NA, invokeMatch(new StringEval("Aaron"), ae, MATCH_LARGEST_LTE)); @@ -181,4 +182,34 @@ confirmInt(12, invokeMatch(BoolEval.TRUE, ae, MATCH_LARGEST_LTE)); } + + /** + * Ensures that the match_type argument can be an AreaEval.
+ * Bugzilla 44421 + */ + public void testMatchArgTypeArea() { + + ValueEval[] values = { + new NumberEval(4), + new NumberEval(5), + new NumberEval(10), + new NumberEval(10), + new NumberEval(25), + }; + + AreaEval ae = createAreaEval("A1:A5", values); + + AreaEval matchAE = createAreaEval("C1:C1", new ValueEval[] { MATCH_LARGEST_LTE, }); + + try { + confirmInt(4, invokeMatch(new NumberEval(10), ae, matchAE)); + } catch (RuntimeException e) { + if(e.getMessage().startsWith("Unexpected match_type type")) { + // identified bug 44421 + fail(e.getMessage()); + } + // some other error ?? + throw e; + } + } }