forked from M-Labs/artiq
1
0
Fork 0

Fix environment corruption by ExceptHandler without a name.

This commit is contained in:
whitequark 2015-07-17 16:04:46 +03:00
parent 2dcb744519
commit 3b661b2b65
1 changed files with 8 additions and 2 deletions

View File

@ -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,6 +178,7 @@ class LocalExtractor(algorithm.Visitor):
def visit_ExceptHandler(self, node):
self.visit(node.type)
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)