diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarExpression.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarExpression.java index 06342cbd03ed..3169563818cb 100644 --- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarExpression.java +++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/expressions/SetVarExpression.java @@ -36,11 +36,17 @@ protected void doVerify(VerificationContext context) { private void setVariableType(DataType newType, VerificationContext context) { DataType existingType = context.getVariable(varName); - if (existingType != null && ! newType.equals(existingType)) { - throw new VerificationException(this, "Cannot set variable '" + varName + "' to type " + newType.getName() + - ": It is already set to type " + existingType.getName()); + DataType mostGeneralType = newType; + if (existingType != null) { + if (existingType.isAssignableTo(newType)) + mostGeneralType = newType; + else if (newType.isAssignableTo(existingType)) + mostGeneralType = existingType; + else + throw new VerificationException(this, "Cannot set variable '" + varName + "' to type " + newType.getName() + + ": It is already set to type " + existingType.getName()); } - context.setVariable(varName, newType); + context.setVariable(varName, mostGeneralType); } @Override