forked from M-Labs/artiq
1
0
Fork 0

Require boolean operand in BoolOp.

This commit is contained in:
whitequark 2015-07-21 23:45:17 +03:00
parent e21829ce74
commit 5d518dcec6
4 changed files with 8 additions and 13 deletions

View File

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

View File

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

View File

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

View File

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