Commit 60be9a7b authored by Mark Florisson's avatar Mark Florisson

Fix fused type -> object compiler crash & resolve fused type variable declarations from modules

parent 0991b1eb
......@@ -799,8 +799,11 @@ class CSimpleBaseTypeNode(CBaseTypeNode):
else:
if self.module_path:
scope = env.find_imported_module(self.module_path, self.pos)
if scope:
scope.fused_to_specific = env.fused_to_specific
else:
scope = env
if scope:
if scope.is_c_class_scope:
scope = scope.global_scope()
......@@ -2757,6 +2760,10 @@ class DefNode(FuncDefNode):
def analyse_argument_types(self, env):
directive_locals = self.directive_locals = env.directives['locals']
allow_none_for_extension_args = env.directives['allow_none_for_extension_args']
f2s = env.fused_to_specific
env.fused_to_specific = None
for arg in self.args:
if hasattr(arg, 'name'):
name_declarator = None
......@@ -2801,6 +2808,8 @@ class DefNode(FuncDefNode):
if arg.or_none:
error(arg.pos, "Only Python type arguments can have 'or None'")
env.fused_to_specific = f2s
def analyse_signature(self, env):
if self.entry.is_special:
if self.decorators:
......
......@@ -1108,7 +1108,7 @@ class CType(PyrexType):
return 0
class FusedType(PyrexType):
class FusedType(CType):
"""
Represents a Fused Type. All it needs to do is keep track of the types
it aggregates, as it will be replaced with its specific version wherever
......@@ -1121,6 +1121,7 @@ class FusedType(PyrexType):
"""
is_fused = 1
exception_check = 0
def __init__(self, types, name=None):
self.types = types
......
# mode: run
cimport cython
from cython cimport integral
from cpython cimport Py_INCREF
......@@ -220,3 +221,24 @@ def test_normal_class():
short 10
"""
NormalClass().method[pure_cython.short](10)
def test_fused_declarations(cython.integral i, cython.floating f):
"""
>>> test_fused_declarations[pure_cython.short, pure_cython.float](5, 6.6)
short
float
25 43.56
>>> test_fused_declarations[pure_cython.long, pure_cython.double](5, 6.6)
long
double
25 43.56
"""
cdef cython.integral squared_int = i * i
cdef cython.floating squared_float = f * f
assert cython.typeof(squared_int) == cython.typeof(i)
assert cython.typeof(squared_float) == cython.typeof(f)
print cython.typeof(squared_int)
print cython.typeof(squared_float)
print '%d %.2f' % (squared_int, squared_float)
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