# Buggy code
def array_angle_kwarg(context, builder, sig, args):
    arg = sig.args[0]
    if isinstance(arg.dtype, types.Complex):
        retty = arg.dtype.underlying_float
    else:
        retty = arg.dtype

    def array_angle_impl(arr, deg=False):
        out = numpy.zeros_like(arr, dtype=retty)
        for index, val in numpy.ndenumerate(arr):
            out[index] = numpy.angle(val, deg)
        return out

    res = context.compile_internal(builder, array_angle_impl, sig, args)
    return impl_ret_new_ref(context, builder, sig.return_type, res)


# Traceback (TypingError)
from numba import jit
@jit(nopython=True)
...: def angle(x): return np.angle(x)
...:

angle(np.complex128([1+1j]))
Traceback (most recent call last):
File "<ipython-input-6-186e6f934ae3>", line 1, in <module>
angle(np.complex128([1+1j]))
File "/home/antoine/numba/numba/dispatcher.py", line 171, in _compile_for_args
return self.compile(sig)
File "/home/antoine/numba/numba/dispatcher.py", line 349, in compile
flags=flags, locals=self.locals)
File "/home/antoine/numba/numba/compiler.py", line 684, in compile_extra
return pipeline.compile_extra(func)
File "/home/antoine/numba/numba/compiler.py", line 372, in compile_extra
return self.compile_bytecode(bc, func_attr=self.func_attr)
File "/home/antoine/numba/numba/compiler.py", line 381, in compile_bytecode
return self._compile_bytecode()
File "/home/antoine/numba/numba/compiler.py", line 665, in _compile_bytecode
res = pm.run(self.status)
File "/home/antoine/numba/numba/compiler.py", line 251, in run
raise patched_exception
File "/home/antoine/numba/numba/compiler.py", line 243, in run
stage()
File "/home/antoine/numba/numba/compiler.py", line 469, in stage_nopython_frontend
self.locals)
File "/home/antoine/numba/numba/compiler.py", line 799, in type_inference_stage
infer.propagate()
File "/home/antoine/numba/numba/typeinfer.py", line 565, in propagate
raise errors[0]
TypingError: Internal error at <numba.typeinfer.CallConstraint object at 0x7fa910005470>:
--%<-----------------------------------------------------------------
Traceback (most recent call last):
File "/home/antoine/numba/numba/typeinfer.py", line 111, in propagate
constraint(typeinfer)
File "/home/antoine/numba/numba/typeinfer.py", line 284, in __call__
self.resolve(typeinfer, typevars, fnty)
File "/home/antoine/numba/numba/typeinfer.py", line 311, in resolve
sig = context.resolve_function_type(fnty, pos_args, kw_args)
File "/home/antoine/numba/numba/typing/context.py", line 123, in resolve_function_type
return func.get_call_type(self, args, kws)
File "/home/antoine/numba/numba/types.py", line 264, in get_call_type
sig = temp.apply(args, kws)
File "/home/antoine/numba/numba/typing/templates.py", line 229, in apply
sig = typer(*args, **kws)
File "/home/antoine/numba/numba/typing/npydecl.py", line 850, in typer
return ref.copy(dtype=ref.underlying_float)
AttributeError: 'Array' object has no attribute 'underlying_float'
--%<-----------------------------------------------------------------

# Fixed code
def array_angle_kwarg(context, builder, sig, args):
    arg = sig.args[0]
    ret_dtype = sig.return_type.dtype

    def array_angle_impl(arr, deg):
        out = numpy.zeros_like(arr, dtype=ret_dtype)
        for index, val in numpy.ndenumerate(arr):
            out[index] = numpy.angle(val, deg)
        return out

    if len(args) == 1:
        args = args + (cgutils.false_bit,)
        sig = signature(sig.return_type, *(sig.args + (types.boolean,)))

    res = context.compile_internal(builder, array_angle_impl, sig, args)
    return impl_ret_new_ref(context, builder, sig.return_type, res)