From: Stefan Behnel Date: Thu, 25 Nov 2010 20:21:31 +0000 (+0100) Subject: fix ticket #598: list comprehensions in closures X-Git-Tag: 0.14.alpha0~79 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2f877a77083fdfee69a11d92e720564eae9ef36a;p=cython.git fix ticket #598: list comprehensions in closures --- diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 92ec2fbd..1f62c06f 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -1287,19 +1287,19 @@ class LocalScope(Scope): entry.original_cname = entry.cname entry.cname = "%s->%s" % (Naming.cur_scope_cname, entry.cname) -class GeneratorExpressionScope(LocalScope): +class GeneratorExpressionScope(Scope): """Scope for generator expressions and comprehensions. As opposed to generators, these can be easily inlined in some cases, so all we really need is a scope that holds the loop variable(s). """ def __init__(self, outer_scope): name = outer_scope.global_scope().next_id(Naming.genexpr_id_ref) - LocalScope.__init__(self, name, outer_scope) + Scope.__init__(self, name, outer_scope, outer_scope) self.directives = outer_scope.directives self.genexp_prefix = "%s%d%s" % (Naming.pyrex_prefix, len(name), name) def mangle(self, prefix, name): - return '%s%s' % (self.genexp_prefix, self.outer_scope.mangle(self, prefix, name)) + return '%s%s' % (self.genexp_prefix, self.parent_scope.mangle(self, prefix, name)) def declare_var(self, name, type, pos, cname = None, visibility = 'private', is_cdef = True): @@ -1308,10 +1308,10 @@ class GeneratorExpressionScope(LocalScope): outer_entry = self.outer_scope.lookup(name) if outer_entry and outer_entry.is_variable: type = outer_entry.type # may still be 'unspecified_type' ! - # the outer scope needs to generate code for the variable, but + # the parent scope needs to generate code for the variable, but # this scope must hold its name exclusively - cname = '%s%s' % (self.genexp_prefix, self.outer_scope.mangle(Naming.var_prefix, name)) - entry = self.outer_scope.declare_var(None, type, pos, cname, visibility, is_cdef = True) + cname = '%s%s' % (self.genexp_prefix, self.parent_scope.mangle(Naming.var_prefix, name)) + entry = self.parent_scope.declare_var(None, type, pos, cname, visibility, is_cdef = True) self.entries[name] = entry return entry diff --git a/tests/bugs.txt b/tests/bugs.txt index 48211a70..9846b259 100644 --- a/tests/bugs.txt +++ b/tests/bugs.txt @@ -17,7 +17,6 @@ function_as_method_T494 closure_inside_cdef_T554 ipow_crash_T562 pure_mode_cmethod_inheritance_T583 -list_comp_in_closure_T598 genexpr_iterable_lookup_T600 # CPython regression tests that don't current work: