Commit e0afd5f8 authored by Stefan Behnel's avatar Stefan Behnel

let generator expressions inherit type declarations from surrounding scope

parent a2e8d257
...@@ -1275,6 +1275,11 @@ class GeneratorExpressionScope(LocalScope): ...@@ -1275,6 +1275,11 @@ class GeneratorExpressionScope(LocalScope):
def declare_var(self, name, type, pos, def declare_var(self, name, type, pos,
cname = None, visibility = 'private', is_cdef = True): cname = None, visibility = 'private', is_cdef = True):
if type is unspecified_type:
# if the outer scope defines a type for this variable, inherit it
outer_entry = self.outer_scope.lookup(name)
if outer_entry and not outer_entry.is_builtin:
type = outer_entry.type # may still be 'unspecified_type' !
# the outer scope needs to generate code for the variable, but # the outer scope needs to generate code for the variable, but
# this scope must hold its name exclusively # this scope must hold its name exclusively
cname = '%s%s' % (self.genexp_prefix, self.outer_scope.mangle(Naming.var_prefix, name)) cname = '%s%s' % (self.genexp_prefix, self.outer_scope.mangle(Naming.var_prefix, name))
......
...@@ -166,9 +166,11 @@ def all_lower_case_characters(unicode ustring): ...@@ -166,9 +166,11 @@ def all_lower_case_characters(unicode ustring):
return all(uchar.islower() for uchar in ustring) return all(uchar.islower() for uchar in ustring)
@cython.test_assert_path_exists("//ForInStatNode", @cython.test_assert_path_exists("//ForInStatNode",
"//InlinedGeneratorExpressionNode") "//InlinedGeneratorExpressionNode",
"//InlinedGeneratorExpressionNode//IfStatNode")
@cython.test_fail_if_path_exists("//SimpleCallNode", @cython.test_fail_if_path_exists("//SimpleCallNode",
"//YieldExprNode") "//YieldExprNode",
"//IfStatNode//CoerceToBooleanNode")
def all_in_typed_gen(seq): def all_in_typed_gen(seq):
""" """
>>> all_in_typed_gen([1,1,1]) >>> all_in_typed_gen([1,1,1])
...@@ -192,15 +194,15 @@ def all_in_typed_gen(seq): ...@@ -192,15 +194,15 @@ def all_in_typed_gen(seq):
4 4
False False
""" """
# FIXME: this isn't really supposed to work, but it currently does
# due to incorrect scoping - this should be fixed!!
cdef int x cdef int x
return all(x for x in seq) return all(x for x in seq)
@cython.test_assert_path_exists("//ForInStatNode", @cython.test_assert_path_exists("//ForInStatNode",
"//InlinedGeneratorExpressionNode") "//InlinedGeneratorExpressionNode",
"//InlinedGeneratorExpressionNode//IfStatNode")
@cython.test_fail_if_path_exists("//SimpleCallNode", @cython.test_fail_if_path_exists("//SimpleCallNode",
"//YieldExprNode") "//YieldExprNode",
"//IfStatNode//CoerceToBooleanNode")
def all_in_nested_gen(seq): def all_in_nested_gen(seq):
""" """
>>> all(x for L in [[1,1,1],[1,1,1],[1,1,1]] for x in L) >>> all(x for L in [[1,1,1],[1,1,1],[1,1,1]] for x in L)
...@@ -243,7 +245,5 @@ def all_in_nested_gen(seq): ...@@ -243,7 +245,5 @@ def all_in_nested_gen(seq):
2 2
False False
""" """
# FIXME: this isn't really supposed to work, but it currently does
# due to incorrect scoping - this should be fixed!!
cdef int x cdef int x
return all(x for L in seq for x in L) return all(x for L in seq for x in L)
...@@ -143,7 +143,8 @@ lower_ustring = mixed_ustring.lower() ...@@ -143,7 +143,8 @@ lower_ustring = mixed_ustring.lower()
upper_ustring = mixed_ustring.upper() upper_ustring = mixed_ustring.upper()
@cython.test_assert_path_exists('//PythonCapiCallNode', @cython.test_assert_path_exists('//PythonCapiCallNode',
'//ForFromStatNode') '//ForFromStatNode',
"//InlinedGeneratorExpressionNode")
@cython.test_fail_if_path_exists('//SimpleCallNode', @cython.test_fail_if_path_exists('//SimpleCallNode',
'//ForInStatNode') '//ForInStatNode')
def any_lower_case_characters(unicode ustring): def any_lower_case_characters(unicode ustring):
...@@ -158,9 +159,11 @@ def any_lower_case_characters(unicode ustring): ...@@ -158,9 +159,11 @@ def any_lower_case_characters(unicode ustring):
return any(uchar.islower() for uchar in ustring) return any(uchar.islower() for uchar in ustring)
@cython.test_assert_path_exists("//ForInStatNode", @cython.test_assert_path_exists("//ForInStatNode",
"//InlinedGeneratorExpressionNode") "//InlinedGeneratorExpressionNode",
"//InlinedGeneratorExpressionNode//IfStatNode")
@cython.test_fail_if_path_exists("//SimpleCallNode", @cython.test_fail_if_path_exists("//SimpleCallNode",
"//YieldExprNode") "//YieldExprNode",
"//IfStatNode//CoerceToBooleanNode")
def any_in_typed_gen(seq): def any_in_typed_gen(seq):
""" """
>>> any_in_typed_gen([0,1,0]) >>> any_in_typed_gen([0,1,0])
...@@ -182,15 +185,15 @@ def any_in_typed_gen(seq): ...@@ -182,15 +185,15 @@ def any_in_typed_gen(seq):
5 5
False False
""" """
# FIXME: this isn't really supposed to work, but it currently does
# due to incorrect scoping - this should be fixed!!
cdef int x cdef int x
return any(x for x in seq) return any(x for x in seq)
@cython.test_assert_path_exists("//ForInStatNode", @cython.test_assert_path_exists("//ForInStatNode",
"//InlinedGeneratorExpressionNode") "//InlinedGeneratorExpressionNode",
"//InlinedGeneratorExpressionNode//IfStatNode")
@cython.test_fail_if_path_exists("//SimpleCallNode", @cython.test_fail_if_path_exists("//SimpleCallNode",
"//YieldExprNode") "//YieldExprNode",
"//IfStatNode//CoerceToBooleanNode")
def any_in_nested_gen(seq): def any_in_nested_gen(seq):
""" """
>>> any(x for L in [[0,0,0],[0,0,1],[0,0,0]] for x in L) >>> any(x for L in [[0,0,0],[0,0,1],[0,0,0]] for x in L)
...@@ -226,7 +229,5 @@ def any_in_nested_gen(seq): ...@@ -226,7 +229,5 @@ def any_in_nested_gen(seq):
3 3
False False
""" """
# FIXME: this isn't really supposed to work, but it currently does
# due to incorrect scoping - this should be fixed!!
cdef int x cdef int x
return any(x for L in seq for x in L) return any(x for L in seq for x in L)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment