Commit c430314b authored by Robert Bradshaw's avatar Robert Bradshaw

Allow composite fused types.

parent 49b732d4
...@@ -1215,8 +1215,6 @@ class FusedTypeNode(CBaseTypeNode): ...@@ -1215,8 +1215,6 @@ class FusedTypeNode(CBaseTypeNode):
if type in types: if type in types:
error(type_node.pos, "Type specified multiple times") error(type_node.pos, "Type specified multiple times")
elif type.is_fused:
error(type_node.pos, "Cannot fuse a fused type")
else: else:
types.append(type) types.append(type)
......
...@@ -1339,7 +1339,13 @@ class FusedType(CType): ...@@ -1339,7 +1339,13 @@ class FusedType(CType):
exception_check = 0 exception_check = 0
def __init__(self, types, name=None): def __init__(self, types, name=None):
self.types = types # Use list rather than set to preserve order.
flattened_types = [t for t in types if not t.is_fused]
subtypes = sum([t.types for t in types if t.is_fused], [])
for type in subtypes:
if type not in flattened_types:
flattened_types.append(type)
self.types = flattened_types
self.name = name self.name = name
def declaration_code(self, entity_code, for_display = 0, def declaration_code(self, entity_code, for_display = 0,
......
...@@ -67,7 +67,6 @@ func(x, y) ...@@ -67,7 +67,6 @@ func(x, y)
_ERRORS = u""" _ERRORS = u"""
10:15: fused_type does not take keyword arguments 10:15: fused_type does not take keyword arguments
15:38: Type specified multiple times 15:38: Type specified multiple times
17:33: Cannot fuse a fused type
26:4: Invalid use of fused types, type cannot be specialized 26:4: Invalid use of fused types, type cannot be specialized
26:4: Not enough types specified to specialize the function, int2_t is still fused 26:4: Not enough types specified to specialize the function, int2_t is still fused
27:4: Invalid use of fused types, type cannot be specialized 27:4: Invalid use of fused types, type cannot be specialized
......
...@@ -19,6 +19,7 @@ other_t = cython.fused_type(int, double) ...@@ -19,6 +19,7 @@ other_t = cython.fused_type(int, double)
ctypedef double *p_double ctypedef double *p_double
ctypedef int *p_int ctypedef int *p_int
fused_type3 = cython.fused_type(int, double) fused_type3 = cython.fused_type(int, double)
fused_composite = cython.fused_type(fused_type2, fused_type3)
def test_pure(): def test_pure():
""" """
...@@ -349,3 +350,17 @@ def test_index_fused_args(cython.floating f, ints_t i): ...@@ -349,3 +350,17 @@ def test_index_fused_args(cython.floating f, ints_t i):
double int double int
""" """
_test_index_fused_args[cython.floating, ints_t](f, i) _test_index_fused_args[cython.floating, ints_t](f, i)
def test_composite(fused_composite x):
"""
>>> test_composite('a')
'a'
>>> test_composite(3)
6
>>> test_composite(3.0)
6.0
"""
if fused_composite is string_t:
return x
else:
return 2 * x
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