# Buggy code
def align_argument_type(self, env, arg):
    # @cython.locals()
    directive_locals = self.directive_locals
    orig_type = arg.type
    if arg.name in directive_locals:
        type_node = directive_locals[arg.name]
        other_type = type_node.analyse_as_type(env)
    elif (
        isinstance(arg, CArgDeclNode)
        and arg.annotation
        and env.directives["annotation_typing"]
    ):
        type_node = arg.annotation
        other_type = arg.inject_type_from_annotations(env)
        if other_type is None:
            return arg
    else:
        return arg
    if other_type is None:
        error(type_node.pos, "Not a type")
    elif other_type.is_fused and any(orig_type.same_as(t) for t in other_type.types):
        pass  # use specialized rather than fused type
    elif orig_type is not py_object_type and not orig_type.same_as(other_type):
        error(arg.base_type.pos, "Signature does not agree with previous declaration")
        error(type_node.pos, "Previous declaration here")
    else:
        arg.type = other_type
    return arg


# 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 align_argument_type(self, env, arg):
    # @cython.locals()
    directive_locals = self.directive_locals
    orig_type = arg.type
    if arg.name in directive_locals:
        type_node = directive_locals[arg.name]
        other_type = type_node.analyse_as_type(env)
    elif (
        isinstance(arg, CArgDeclNode)
        and arg.annotation
        and env.directives["annotation_typing"]
    ):
        type_node = arg.annotation
        other_type = arg.inject_type_from_annotations(env)
        if other_type is None:
            return arg
    else:
        return arg
    if other_type is None:
        error(type_node.pos, "Not a type")
    elif orig_type is not py_object_type and not orig_type.same_as(other_type):
        error(arg.base_type.pos, "Signature does not agree with previous declaration")
        error(type_node.pos, "Previous declaration here")
    else:
        arg.type = other_type
    return arg