Commit c17bdb28 authored by Mark Florisson's avatar Mark Florisson

Disallow fused lambdas (doesn't make sense) & fix fused def in normal classes

parent bfc6469a
......@@ -2540,7 +2540,7 @@ def __pyx_fused_cpdef(signatures, args, kwargs):
py_func.doc = orig_py_func.doc
# ... and the symbol table
del env.entries['__pyx_fused_cpdef']
env.entries.pop('__pyx_fused_cpdef', None)
if is_def:
env.entries[e.name] = e
else:
......
......@@ -1383,6 +1383,7 @@ if VALUE is not None:
""")
fused_function = None
in_lambda = 0
def __call__(self, root):
self.env_stack = [root.scope]
......@@ -1403,8 +1404,10 @@ if VALUE is not None:
return node
def visit_LambdaNode(self, node):
self.in_lambda += 1
node.analyse_declarations(self.env_stack[-1])
self.visitchildren(node)
self.in_lambda -= 1
return node
def visit_ClassDefNode(self, node):
......@@ -1458,9 +1461,12 @@ if VALUE is not None:
body=Nodes.PassStatNode(node.pos))
if node.has_fused_arguments:
if self.fused_function:
if self.fused_function or self.in_lambda:
if self.fused_function not in self.fused_error_funcs:
error(node.pos, "Cannot nest fused functions")
if self.in_lambda:
error(node.pos, "Fused lambdas not allowed")
else:
error(node.pos, "Cannot nest fused functions")
self.fused_error_funcs.add(self.fused_function)
# env.declare_var(node.name, PyrexTypes.py_object_type, node.pos)
......
......@@ -18,7 +18,7 @@ def generator(cython.integral i):
_ERRORS = u"""
e_fused_closure.pyx:6:4: Cannot nest fused functions
e_fused_closure.pyx:10:11: Cannot nest fused functions
e_fused_closure.pyx:14:15: Cannot nest fused functions
e_fused_closure.pyx:10:11: Fused lambdas not allowed
e_fused_closure.pyx:14:15: Fused lambdas not allowed
e_fused_closure.pyx:16:0: Fused generators not supported
"""
......@@ -36,6 +36,8 @@ ctypedef fused memslice_dtype_t:
def f(memslice_dtype_t[:, :] a):
pass
lambda cython.integral i: i
# This is all valid
dtype5 = fused_type(int, long, float)
dtype6 = cython.fused_type(int, long)
......@@ -61,4 +63,5 @@ fused_types.pyx:28:16: Call with wrong number of arguments (expected 2, got 1)
fused_types.pyx:29:16: Call with wrong number of arguments (expected 2, got 3)
fused_types.pyx:30:4: Keyword and starred arguments not allowed in cdef functions.
fused_types.pyx:36:6: Invalid base type for memoryview slice: int *
fused_types.pyx:39:0: Fused lambdas not allowed
"""
......@@ -210,3 +210,13 @@ def test_opt_args():
opt_args[int, float](3, 4.0)
opt_args[int, double](3, 4.0)
class NormalClass(object):
def method(self, cython.integral i):
print cython.typeof(i), i
def test_normal_class():
"""
>>> test_normal_class()
short 10
"""
NormalClass().method[pure_cython.short](10)
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