Commit 03f1a3ce authored by Stefan Behnel's avatar Stefan Behnel

test that functions that do not need a closure know they do not need it

parent 8f516cc5
cimport cython
def add_n(int n): def add_n(int n):
""" """
>>> f = add_n(3) >>> f = add_n(3)
...@@ -185,6 +187,12 @@ def more_inner_funcs(x): ...@@ -185,6 +187,12 @@ def more_inner_funcs(x):
return f(a_f), g(b_g), h(b_h) return f(a_f), g(b_g), h(b_h)
return resolve return resolve
@cython.test_assert_path_exists("//DefNode//DefNode//DefNode//DefNode",
"//DefNode[@needs_outer_scope = False]", # deep_inner()
"//DefNode//DefNode//DefNode//DefNode[@needs_closure = False]", # h()
)
@cython.test_fail_if_path_exists("//DefNode//DefNode[@needs_outer_scope = False]")
def deep_inner(): def deep_inner():
""" """
>>> deep_inner()() >>> deep_inner()()
...@@ -199,6 +207,12 @@ def deep_inner(): ...@@ -199,6 +207,12 @@ def deep_inner():
return g() return g()
return f() return f()
@cython.test_assert_path_exists("//DefNode//DefNode//DefNode",
"//DefNode//DefNode//DefNode[@needs_outer_scope = False]", # a()
"//DefNode//DefNode//DefNode[@needs_closure = False]", # a(), g(), h()
)
@cython.test_fail_if_path_exists("//DefNode//DefNode//DefNode[@needs_closure = True]") # a(), g(), h()
def deep_inner_sibling(): def deep_inner_sibling():
""" """
>>> deep_inner_sibling()() >>> deep_inner_sibling()()
...@@ -206,8 +220,10 @@ def deep_inner_sibling(): ...@@ -206,8 +220,10 @@ def deep_inner_sibling():
""" """
cdef int x = 1 cdef int x = 1
def f(): def f():
def a():
return 1
def g(): def g():
return x+1 return x+a()
def h(): def h():
return g() return g()
return h return h
......
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