# Buggy code
def _specialize_function_args(self, args, fused_to_specific):
    for arg in args:
        if arg.type.is_fused:
            arg.type = arg.type.specialize(fused_to_specific)
            if arg.type.is_memoryviewslice:
                arg.type.validate_memslice_dtype(arg.pos)


# Traceback (Cython.Compiler.Errors.CompileError)
Compiling bug.py because it changed.
[1/1] Cythonizing bug.py

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
arr = np.empty_like(arg)
^
------------------------------------------------------------

bug.py:4:23: Cannot coerce to a type that is not specialized

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
arr = np.empty_like(arg)
return arr
^
------------------------------------------------------------

bug.py:5:11: Type is not specialized

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
arr = np.empty_like(arg)
^
------------------------------------------------------------

bug.py:4:23: Cannot coerce to a type that is not specialized

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
arr = np.empty_like(arg)
return arr
^
------------------------------------------------------------

bug.py:5:11: Type is not specialized

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
arr = np.empty_like(arg)
^
------------------------------------------------------------

bug.py:4:4: Invalid use of fused types, type cannot be specialized

Error compiling Cython file:
------------------------------------------------------------
...
import numpy as np

def func(arg):
arr = np.empty_like(arg)
^
------------------------------------------------------------

bug.py:4:4: Invalid use of fused types, type cannot be specialized
Traceback (most recent call last):
File "/home/users/augier3pi/.pyenv/versions/3.7.3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/users/augier3pi/.pyenv/versions/3.7.3/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/users/augier3pi/Dev/transonic/transonic_cl/cythonize.py", line 11, in <module>
ext_modules=cythonize(path, language_level=3), include_dirs=[np.get_include()]
File "/home/users/augier3pi/.pyenv/versions/3.7.3/lib/python3.7/site-packages/Cython/Build/Dependencies.py", line 1096, in cythonize
cythonize_one(*args)
File "/home/users/augier3pi/.pyenv/versions/3.7.3/lib/python3.7/site-packages/Cython/Build/Dependencies.py", line 1219, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: bug.py

# Fixed code
def _specialize_function_args(self, args, fused_to_specific):
    for arg in args:
        if arg.type.is_fused:
            arg.type = arg.type.specialize(fused_to_specific)
            if arg.type.is_memoryviewslice:
                arg.type.validate_memslice_dtype(arg.pos)
            if arg.annotation:
                # TODO might be nice if annotations were specialized instead?
                # (Or might be hard to do reliably)
                arg.annotation.untyped = True