Revert "Require boolean operand in BoolOp."

This reverts commit 5d518dcec6.
This commit is contained in:
whitequark 2015-07-22 18:35:18 +03:00
parent 51aef980a0
commit de181e0cb9
4 changed files with 14 additions and 9 deletions

View File

@ -305,7 +305,7 @@ class ASTTypedRewriter(algorithm.Transformer):
def visit_BoolOp(self, node):
node = self.generic_visit(node)
node = asttyped.BoolOpT(type=builtins.TBool(),
node = asttyped.BoolOpT(type=types.TVar(),
op=node.op, values=node.values,
op_locs=node.op_locs, loc=node.loc)
return self.visit(node)

View File

@ -154,8 +154,8 @@ class Inferencer(algorithm.Visitor):
def visit_BoolOpT(self, node):
self.generic_visit(node)
for value in node.values:
self._unify(value.type, builtins.TBool(),
value.loc, None)
self._unify(node.type, value.type,
node.loc, value.loc, self._makenotes_elts(node.values, "an operand"))
def visit_UnaryOpT(self, node):
self.generic_visit(node)

View File

@ -14,6 +14,8 @@ a = b
# CHECK-L: ${LINE:+1}: error: cannot unify int(width='a) with bool
1 and False
# CHECK-L: note: an operand of type int(width='a)
# CHECK-L: note: an operand of type bool
# CHECK-L: ${LINE:+1}: error: expected unary '+' operand to be of numeric type, not list(elt='a)
+[]

View File

@ -39,17 +39,20 @@ j += [1.0]
True and False
# CHECK-L: True:bool and False:bool:bool
~1
# CHECK-L: ~1:int(width='g):int(width='g)
1 and 0
# CHECK-L: 1:int(width='g) and 0:int(width='g):int(width='g)
not True
# CHECK-L: not True:bool:bool
~1
# CHECK-L: 1:int(width='h):int(width='h)
not 1
# CHECK-L: 1:int(width='i):bool
[x for x in [1]]
# CHECK-L: [x:int(width='h) for x:int(width='h) in [1:int(width='h)]:list(elt=int(width='h))]:list(elt=int(width='h))
# CHECK-L: [x:int(width='j) for x:int(width='j) in [1:int(width='j)]:list(elt=int(width='j))]:list(elt=int(width='j))
lambda x, y=1: x
# CHECK-L: lambda x:'i, y:int(width='j)=1:int(width='j): x:'i:(x:'i, ?y:int(width='j))->'i
# CHECK-L: lambda x:'k, y:int(width='l)=1:int(width='l): x:'k:(x:'k, ?y:int(width='l))->'k
k = "x"
# CHECK-L: k:str