From 3b661b2b6501cfa4e8633f9e74c7493ecd0475b8 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 17 Jul 2015 16:04:46 +0300 Subject: [PATCH] Fix environment corruption by ExceptHandler without a name. --- artiq/compiler/transforms/asttyped_rewriter.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/artiq/compiler/transforms/asttyped_rewriter.py b/artiq/compiler/transforms/asttyped_rewriter.py index 13527ba52..244f99fd0 100644 --- a/artiq/compiler/transforms/asttyped_rewriter.py +++ b/artiq/compiler/transforms/asttyped_rewriter.py @@ -92,6 +92,7 @@ class LocalExtractor(algorithm.Visitor): self.visit_root(node) def _assignable(self, name): + assert name is not None if name not in self.typing_env and name not in self.nonlocal_: self.typing_env[name] = types.TVar() @@ -177,7 +178,8 @@ class LocalExtractor(algorithm.Visitor): def visit_ExceptHandler(self, node): self.visit(node.type) - self._assignable(node.name) + if node.name is not None: + self._assignable(node.name) for stmt in node.body: self.visit(stmt) @@ -383,8 +385,12 @@ class ASTTypedRewriter(algorithm.Transformer): def visit_ExceptHandler(self, node): node = self.generic_visit(node) + if node.name is not None: + name_type = self._find_name(node.name, node.name_loc) + else: + name_type = types.TVar() node = asttyped.ExceptHandlerT( - name_type=self._find_name(node.name, node.name_loc), + name_type=name_type, filter=node.type, name=node.name, body=node.body, except_loc=node.except_loc, as_loc=node.as_loc, name_loc=node.name_loc, colon_loc=node.colon_loc, loc=node.loc)