diff --git a/artiq/compiler/transforms/artiq_ir_generator.py b/artiq/compiler/transforms/artiq_ir_generator.py index d341b4225..2ee7b448c 100644 --- a/artiq/compiler/transforms/artiq_ir_generator.py +++ b/artiq/compiler/transforms/artiq_ir_generator.py @@ -451,6 +451,7 @@ class ARTIQIRGenerator(algorithm.Visitor): self.current_block = head old_continue, self.continue_target = self.continue_target, head cond = self.visit(node.test) + cond = self.coerce_to_bool(cond) post_head = self.current_block break_block = self.add_block("while.break") diff --git a/artiq/test/lit/integration/if.py b/artiq/test/lit/integration/if.py index fab6c3df0..8d8eec4f2 100644 --- a/artiq/test/lit/integration/if.py +++ b/artiq/test/lit/integration/if.py @@ -19,3 +19,9 @@ else: assert (0 if True else 1) == 0 assert (0 if False else 1) == 1 + +if 0: + assert True + +if 1: + assert True diff --git a/artiq/test/lit/integration/while.py b/artiq/test/lit/integration/while.py index e7d03c0d7..397055c9a 100644 --- a/artiq/test/lit/integration/while.py +++ b/artiq/test/lit/integration/while.py @@ -53,3 +53,10 @@ while True: assert False else: assert False + +while 0: + assert False + +while 1: + assert True + break