Commit fdd78468 authored by Stefan Behnel's avatar Stefan Behnel

support genexp loop variables that override builtin names or global functions etc.

parent 0948e79c
...@@ -1278,7 +1278,7 @@ class GeneratorExpressionScope(LocalScope): ...@@ -1278,7 +1278,7 @@ class GeneratorExpressionScope(LocalScope):
if type is unspecified_type: if type is unspecified_type:
# if the outer scope defines a type for this variable, inherit it # if the outer scope defines a type for this variable, inherit it
outer_entry = self.outer_scope.lookup(name) outer_entry = self.outer_scope.lookup(name)
if outer_entry and not outer_entry.is_builtin: if outer_entry and outer_entry.is_variable:
type = outer_entry.type # may still be 'unspecified_type' ! 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
......
...@@ -51,6 +51,7 @@ def any_item(x): ...@@ -51,6 +51,7 @@ def any_item(x):
""" """
return any(x) return any(x)
@cython.test_assert_path_exists("//ForInStatNode", @cython.test_assert_path_exists("//ForInStatNode",
"//InlinedGeneratorExpressionNode") "//InlinedGeneratorExpressionNode")
@cython.test_fail_if_path_exists("//SimpleCallNode", @cython.test_fail_if_path_exists("//SimpleCallNode",
...@@ -78,6 +79,7 @@ def any_in_simple_gen(seq): ...@@ -78,6 +79,7 @@ def any_in_simple_gen(seq):
""" """
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")
@cython.test_fail_if_path_exists("//SimpleCallNode", @cython.test_fail_if_path_exists("//SimpleCallNode",
...@@ -108,6 +110,7 @@ def any_in_simple_gen_scope(seq): ...@@ -108,6 +110,7 @@ def any_in_simple_gen_scope(seq):
assert x == 'abc' assert x == 'abc'
return result return result
@cython.test_assert_path_exists("//ForInStatNode", @cython.test_assert_path_exists("//ForInStatNode",
"//InlinedGeneratorExpressionNode") "//InlinedGeneratorExpressionNode")
@cython.test_fail_if_path_exists("//SimpleCallNode", @cython.test_fail_if_path_exists("//SimpleCallNode",
...@@ -142,6 +145,7 @@ mixed_ustring = u'AbcDefGhIjKlmnoP' ...@@ -142,6 +145,7 @@ mixed_ustring = u'AbcDefGhIjKlmnoP'
lower_ustring = mixed_ustring.lower() 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") "//InlinedGeneratorExpressionNode")
...@@ -158,6 +162,7 @@ def any_lower_case_characters(unicode ustring): ...@@ -158,6 +162,7 @@ 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") "//InlinedGeneratorExpressionNode//IfStatNode")
...@@ -188,6 +193,36 @@ def any_in_typed_gen(seq): ...@@ -188,6 +193,36 @@ def any_in_typed_gen(seq):
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",
"//InlinedGeneratorExpressionNode",
"//InlinedGeneratorExpressionNode//IfStatNode")
@cython.test_fail_if_path_exists("//SimpleCallNode",
"//YieldExprNode")
def any_in_gen_builtin_name(seq):
"""
>>> any_in_gen_builtin_name([0,1,0])
True
>>> any_in_gen_builtin_name([0,0,0])
False
>>> any_in_gen_builtin_name(VerboseGetItem([0,0,1,0,0]))
0
1
2
True
>>> any_in_gen_builtin_name(VerboseGetItem([0,0,0,0,0]))
0
1
2
3
4
5
False
"""
return any(type for type in seq)
@cython.test_assert_path_exists("//ForInStatNode", @cython.test_assert_path_exists("//ForInStatNode",
"//InlinedGeneratorExpressionNode", "//InlinedGeneratorExpressionNode",
"//InlinedGeneratorExpressionNode//IfStatNode") "//InlinedGeneratorExpressionNode//IfStatNode")
......
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