summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-02-02 13:24:45 +0100
committerJon Bratseth <bratseth@oath.com>2018-02-02 13:24:45 +0100
commitc288092ac9868efae10437a8c60974050e9fa799 (patch)
tree537e666d2c5ae7b06fa6e7b4f7ed33b6bb66d013 /searchlib
parent468e0e16a60a5feaf6d5eec971ff06078b6bb694 (diff)
Generalize dimension-wise
Diffstat (limited to 'searchlib')
-rwxr-xr-xsearchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/IfNode.java12
-rw-r--r--searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/TypeResolutionTestCase.java3
2 files changed, 8 insertions, 7 deletions
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/IfNode.java b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/IfNode.java
index 4f0ebc1c7e5..66b250736e8 100755
--- a/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/IfNode.java
+++ b/searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/IfNode.java
@@ -78,13 +78,11 @@ public final class IfNode extends CompositeNode {
public TensorType type(TypeContext context) {
TensorType trueType = trueExpression.type(context);
TensorType falseType = falseExpression.type(context);
-
- // Types of each branch must be compatible; the resulting type is the most general
- if (trueType.isAssignableTo(falseType)) return falseType;
- if (falseType.isAssignableTo(trueType)) return trueType;
- throw new IllegalArgumentException("An if expression must produce compatible types in both " +
- "alternatives, but the 'true' type is " + trueType + " while the " +
- "'false' type is " + falseType);
+ return trueType.dimensionwiseGeneralizationWith(falseType).orElseThrow(() ->
+ new IllegalArgumentException("An if expression must produce compatible types in both " +
+ "alternatives, but the 'true' type is " + trueType + " while the " +
+ "'false' type is " + falseType)
+ );
}
@Override
diff --git a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/TypeResolutionTestCase.java b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/TypeResolutionTestCase.java
index d1ea0fcf2e4..5cac2215a00 100644
--- a/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/TypeResolutionTestCase.java
+++ b/searchlib/src/test/java/com/yahoo/searchlib/rankingexpression/evaluation/TypeResolutionTestCase.java
@@ -22,9 +22,12 @@ public class TypeResolutionTestCase {
context.setType("query('x1')", TensorType.fromSpec("tensor(x[])"));
context.setType("query('x2')", TensorType.fromSpec("tensor(x[10])"));
context.setType("query('y1')", TensorType.fromSpec("tensor(y[])"));
+ context.setType("query('xy1')", TensorType.fromSpec("tensor(x[10],y[])"));
+ context.setType("query('xy2')", TensorType.fromSpec("tensor(x[],y[10])"));
assertType("tensor(x[])", "query(x1)", context);
assertType("tensor(x[])", "if (1>0, query(x1), query(x2))", context);
+ assertType("tensor(x[],y[])", "if (1>0, query(xy1), query(xy2))", context);
assertIncompatibleType("if (1>0, query(x1), query(y1))", context);
}