# Buggy code
def visit_FuncDefNode(self, node):
    """
    Analyse a function and its body, as that hasn't happened yet.  Also
    analyse the directive_locals set by @cython.locals().

    Then, if we are a function with fused arguments, replace the function
    (after it has declared itself in the symbol table!) with a
    FusedCFuncDefNode, and analyse its children (which are in turn normal
    functions). If we're a normal function, just analyse the body of the
    function.
    """
    env = self.current_env()

    self.seen_vars_stack.append(set())
    lenv = node.local_scope
    node.declare_arguments(lenv)

    # @cython.locals(...)
    for var, type_node in node.directive_locals.items():
        if not lenv.lookup_here(var):  # don't redeclare args
            type = type_node.analyse_as_type(lenv)
            if type:
                lenv.declare_var(var, type, type_node.pos)
            else:
                error(type_node.pos, "Not a type")

    if self._handle_fused(node):
        node = self._create_fused_function(env, node)
    else:
        node.body.analyse_declarations(lenv)
        self._handle_nogil_cleanup(lenv, node)
        self._super_visit_FuncDefNode(node)

    self.seen_vars_stack.pop()
    return node


# 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 visit_FuncDefNode(self, node):
    """
    Analyse a function and its body, as that hasn't happened yet.  Also
    analyse the directive_locals set by @cython.locals().

    Then, if we are a function with fused arguments, replace the function
    (after it has declared itself in the symbol table!) with a
    FusedCFuncDefNode, and analyse its children (which are in turn normal
    functions). If we're a normal function, just analyse the body of the
    function.
    """
    env = self.current_env()

    self.seen_vars_stack.append(set())
    lenv = node.local_scope
    node.declare_arguments(lenv)

    # @cython.locals(...)
    for var, type_node in node.directive_locals.items():
        if not lenv.lookup_here(var):  # don't redeclare args
            type = type_node.analyse_as_type(lenv)
            if type and type.is_fused and lenv.fused_to_specific:
                type = type.specialize(lenv.fused_to_specific)
            if type:
                lenv.declare_var(var, type, type_node.pos)
            else:
                error(type_node.pos, "Not a type")

    if self._handle_fused(node):
        node = self._create_fused_function(env, node)
    else:
        node.body.analyse_declarations(lenv)
        self._handle_nogil_cleanup(lenv, node)
        self._super_visit_FuncDefNode(node)

    self.seen_vars_stack.pop()
    return node