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