From bcd18322035d7f9272e1ed1d0050fede6aa0c665 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 16 Jul 2015 15:59:59 +0300 Subject: [PATCH] Ensure bindings are created in correct order for e.g. "x, y = y, x". --- artiq/compiler/transforms/asttyped_rewriter.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/artiq/compiler/transforms/asttyped_rewriter.py b/artiq/compiler/transforms/asttyped_rewriter.py index 094bce534..13527ba52 100644 --- a/artiq/compiler/transforms/asttyped_rewriter.py +++ b/artiq/compiler/transforms/asttyped_rewriter.py @@ -107,12 +107,25 @@ class LocalExtractor(algorithm.Visitor): def visit_Name(self, node): if self.in_assign: - # code like: + # Code like: # x = 1 # def f(): # x = 1 # creates a new binding for x in f's scope self._assignable(node.id) + else: + # This is duplicated here as well as below so that + # code like: + # x, y = y, x + # where y and x were not defined earlier would be invalid. + if node.id in self.typing_env: + return + for outer_env in reversed(self.env_stack): + if node.id in outer_env: + return + diag = diagnostic.Diagnostic("fatal", + "name '{name}' is not bound to anything", {"name":node.id}, node.loc) + self.engine.process(diag) def visit_Attribute(self, node): self.visit_in_assign(node.value, in_assign=False)