Skip to content

Commit

Permalink
Skylark: Static checks allows None value everywhere.
Browse files Browse the repository at this point in the history
--
MOS_MIGRATED_REVID=88713932
  • Loading branch information
laurentlb authored and hanwen committed Mar 16, 2015
1 parent 45c0f11 commit 65ec957
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'}");
Expand Down

0 comments on commit 65ec957

Please sign in to comment.