diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BinaryOperatorExpression.java b/src/main/java/com/google/devtools/build/lib/syntax/BinaryOperatorExpression.java index 57df6483e25bb5..2f1846ff6f84c6 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/BinaryOperatorExpression.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/BinaryOperatorExpression.java @@ -284,8 +284,8 @@ public void accept(SyntaxTreeVisitor visitor) { @Override SkylarkType validate(ValidationEnvironment env) throws EvalException { - SkylarkType ltype = lhs.validate(env); - SkylarkType rtype = rhs.validate(env); + SkylarkType ltype = SkylarkType.typeForInference(lhs.validate(env)); + SkylarkType rtype = SkylarkType.typeForInference(rhs.validate(env)); switch (operator) { case AND: { diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkType.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkType.java index 1bd5908cddab58..9f1d99a51446d6 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkType.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkType.java @@ -594,7 +594,7 @@ public void setReturnType(SkylarkType newReturnType, Location newLoc) throws Eva * @param type a SkylarkType suitable for runtime type checking. * @return the corresponding SkylarkType suitable for a type validation. */ - private static SkylarkType typeForInference(SkylarkType type) { + public static SkylarkType typeForInference(SkylarkType type) { return type == NONE ? TOP : type; } diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ValidationTests.java b/src/test/java/com/google/devtools/build/lib/syntax/ValidationTests.java index d235100992b1da..a01002468782e4 100644 --- a/src/test/java/com/google/devtools/build/lib/syntax/ValidationTests.java +++ b/src/test/java/com/google/devtools/build/lib/syntax/ValidationTests.java @@ -397,6 +397,15 @@ public void testNoneAssignmentError() throws Exception { + " a = 'b'\n"); } + @Test + public void testNoneIsAnyType() throws Exception { + parse("None + None"); + parse("2 == None"); + parse("None > 'a'"); + parse("[] in None"); + parse("5 * None"); + } + @Test public void testDictComprehensionNotOnList() throws Exception { checkError("Dict comprehension elements must be a list", "{k : k for k in 'abc'}");