# Buggy code
def scalar_angle_kwarg(context, builder, sig, args):
    def scalar_angle_impl(val, deg=False):
        if deg:
            scal = 180 / numpy.pi
            return numpy.arctan2(val.imag, val.real) * scal
        else:
            return numpy.arctan2(val.imag, val.real)

    res = context.compile_internal(builder, scalar_angle_impl, sig, args)
    return impl_ret_untracked(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 scalar_angle_kwarg(context, builder, sig, args):
    deg_mult = sig.return_type(180 / numpy.pi)

    def scalar_angle_impl(val, deg):
        if deg:
            return numpy.arctan2(val.imag, val.real) * deg_mult
        else:
            return numpy.arctan2(val.imag, val.real)

    if len(args) == 1:
        args = args + (cgutils.false_bit,)
        sig = signature(sig.return_type, *(sig.args + (types.boolean,)))
    res = context.compile_internal(builder, scalar_angle_impl, sig, args)
    return impl_ret_untracked(context, builder, sig.return_type, res)