Commit 2a160845 authored by Stefan Behnel's avatar Stefan Behnel

Work around compiler crash due to missing 'env' (before declaration analysis)...

Work around compiler crash due to missing 'env' (before declaration analysis) when combining @ccall with argument annotations.
parent 1e5fca88
...@@ -867,7 +867,8 @@ class CArgDeclNode(Node): ...@@ -867,7 +867,8 @@ class CArgDeclNode(Node):
base_type = base_type.base_type base_type = base_type.base_type
# inject type declaration from annotations # inject type declaration from annotations
if self.annotation and env.directives['annotation_typing'] and self.base_type.name is None: # FIXME: this is called without 'env' by AdjustDefByDirectives transform before declaration analysis
if self.annotation and (not env or env.directives['annotation_typing']) and self.base_type.name is None:
arg_type = self.inject_type_from_annotations(env) arg_type = self.inject_type_from_annotations(env)
if arg_type is not None: if arg_type is not None:
base_type = arg_type base_type = arg_type
......
...@@ -2324,16 +2324,19 @@ class AdjustDefByDirectives(CythonTransform, SkipDeclarations): ...@@ -2324,16 +2324,19 @@ class AdjustDefByDirectives(CythonTransform, SkipDeclarations):
modifiers = [] modifiers = []
if 'inline' in self.directives: if 'inline' in self.directives:
modifiers.append('inline') modifiers.append('inline')
return_type_node = self.directives.get('returns')
if return_type_node is None and self.directives['annotation_typing']:
return_type_node = node.return_type_annotation
if 'ccall' in self.directives: if 'ccall' in self.directives:
node = node.as_cfunction( node = node.as_cfunction(
overridable=True, returns=self.directives.get('returns'), modifiers=modifiers) overridable=True, returns=return_type_node, modifiers=modifiers)
return self.visit(node) return self.visit(node)
if 'cfunc' in self.directives: if 'cfunc' in self.directives:
if self.in_py_class: if self.in_py_class:
error(node.pos, "cfunc directive is not allowed here") error(node.pos, "cfunc directive is not allowed here")
else: else:
node = node.as_cfunction( node = node.as_cfunction(
overridable=False, returns=self.directives.get('returns'), modifiers=modifiers) overridable=False, returns=return_type_node, modifiers=modifiers)
return self.visit(node) return self.visit(node)
if 'inline' in modifiers: if 'inline' in modifiers:
error(node.pos, "Python functions cannot be declared 'inline'") error(node.pos, "Python functions cannot be declared 'inline'")
......
...@@ -117,6 +117,7 @@ def return_tuple_for_carray() -> tuple: ...@@ -117,6 +117,7 @@ def return_tuple_for_carray() -> tuple:
MyStruct = cython.struct(x=cython.int, y=cython.int, data=cython.double) MyStruct = cython.struct(x=cython.int, y=cython.int, data=cython.double)
@cython.ccall
def struct_io(s : MyStruct) -> MyStruct: def struct_io(s : MyStruct) -> MyStruct:
""" """
>>> d = struct_io(dict(x=1, y=2, data=3)) >>> d = struct_io(dict(x=1, y=2, data=3))
...@@ -128,6 +129,22 @@ def struct_io(s : MyStruct) -> MyStruct: ...@@ -128,6 +129,22 @@ def struct_io(s : MyStruct) -> MyStruct:
return t return t
@cython.test_fail_if_path_exists(
"//CoerceFromPyTypeNode",
"//SimpleCallNode//CoerceToPyTypeNode",
)
@cython.test_assert_path_exists(
"//CoerceToPyTypeNode",
"//CoerceToPyTypeNode//SimpleCallNode",
)
def call_struct_io(s : MyStruct) -> MyStruct:
"""
>>> d = call_struct_io(dict(x=1, y=2, data=3))
>>> sorted(d.items())
[('data', 3.0), ('x', 2), ('y', 1)]
"""
return struct_io(s)
_WARNINGS = """ _WARNINGS = """
8:32: Strings should no longer be used for type declarations. Use 'cython.int' etc. directly. 8:32: Strings should no longer be used for type declarations. Use 'cython.int' etc. directly.
...@@ -138,4 +155,5 @@ _WARNINGS = """ ...@@ -138,4 +155,5 @@ _WARNINGS = """
8:85: Strings should no longer be used for type declarations. Use 'cython.int' etc. directly. 8:85: Strings should no longer be used for type declarations. Use 'cython.int' etc. directly.
# BUG: # BUG:
46:6: 'pytypes_cpdef' redeclared 46:6: 'pytypes_cpdef' redeclared
121:0: 'struct_io' redeclared
""" """
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