From 5d518dcec65a891ba324fe4c5c243c35ecb5afca Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 21 Jul 2015 23:45:17 +0300 Subject: [PATCH] Require boolean operand in BoolOp. --- artiq/compiler/transforms/asttyped_rewriter.py | 2 +- artiq/compiler/transforms/inferencer.py | 4 ++-- lit-test/compiler/inferencer/error_unify.py | 2 -- lit-test/compiler/inferencer/unify.py | 13 +++++-------- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/artiq/compiler/transforms/asttyped_rewriter.py b/artiq/compiler/transforms/asttyped_rewriter.py index df0b46d91..a1d0b7bd6 100644 --- a/artiq/compiler/transforms/asttyped_rewriter.py +++ b/artiq/compiler/transforms/asttyped_rewriter.py @@ -305,7 +305,7 @@ class ASTTypedRewriter(algorithm.Transformer): def visit_BoolOp(self, 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_locs=node.op_locs, loc=node.loc) return self.visit(node) diff --git a/artiq/compiler/transforms/inferencer.py b/artiq/compiler/transforms/inferencer.py index 3fe2972b2..a821059a9 100644 --- a/artiq/compiler/transforms/inferencer.py +++ b/artiq/compiler/transforms/inferencer.py @@ -155,8 +155,8 @@ class Inferencer(algorithm.Visitor): def visit_BoolOpT(self, node): self.generic_visit(node) for value in node.values: - self._unify(node.type, value.type, - node.loc, value.loc, self._makenotes_elts(node.values, "an operand")) + self._unify(value.type, builtins.TBool(), + value.loc, None) def visit_UnaryOpT(self, node): self.generic_visit(node) diff --git a/lit-test/compiler/inferencer/error_unify.py b/lit-test/compiler/inferencer/error_unify.py index dd5c617a8..374c2603c 100644 --- a/lit-test/compiler/inferencer/error_unify.py +++ b/lit-test/compiler/inferencer/error_unify.py @@ -14,8 +14,6 @@ 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) +[] diff --git a/lit-test/compiler/inferencer/unify.py b/lit-test/compiler/inferencer/unify.py index 59abd4262..85db30cb4 100644 --- a/lit-test/compiler/inferencer/unify.py +++ b/lit-test/compiler/inferencer/unify.py @@ -39,20 +39,17 @@ j += [1.0] True and False # 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 -# CHECK-L: 1:int(width='h):int(width='h) +# CHECK-L: ~1:int(width='g):int(width='g) -not 1 -# CHECK-L: 1:int(width='i):bool +not True +# CHECK-L: not True:bool:bool [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 -# 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" # CHECK-L: k:str