# Buggy code
def _init_casting_rules(tm):
    tcr = TypeCastingRules(tm)
    tcr.safe_unsafe(types.boolean, types.int8)
    tcr.safe_unsafe(types.boolean, types.uint8)

    tcr.promote_unsafe(types.int8, types.int16)
    tcr.promote_unsafe(types.uint8, types.uint16)

    tcr.promote_unsafe(types.int16, types.int32)
    tcr.promote_unsafe(types.uint16, types.uint32)

    tcr.promote_unsafe(types.int32, types.int64)
    tcr.promote_unsafe(types.uint32, types.uint64)

    tcr.safe_unsafe(types.uint8, types.int16)
    tcr.safe_unsafe(types.uint16, types.int32)
    tcr.safe_unsafe(types.uint32, types.int64)

    tcr.safe_unsafe(types.int32, types.float64)

    tcr.unsafe_unsafe(types.int32, types.float32)
    # XXX this is inconsistent with the above; but we want to prefer
    # float64 over int64 when typing a heterogenous operation,
    # e.g. `float64 + int64`.  Perhaps we need more granularity in the
    # conversion kinds.
    tcr.safe_unsafe(types.int64, types.float64)
    tcr.safe_unsafe(types.uint64, types.float64)

    tcr.promote_unsafe(types.float32, types.float64)

    tcr.safe(types.float32, types.complex64)
    tcr.safe(types.float64, types.complex128)

    tcr.promote_unsafe(types.complex64, types.complex128)

    # Allow integers to cast ot void*
    tcr.unsafe_unsafe(types.uintp, types.voidptr)

    return tcr


# Traceback (AssertionError)
def f(): return [True]
...
ff = jit(nopython=True)(f)
ff()
Traceback (most recent call last):
File "/home/antoine/numba/numba/lowering.py", line 173, in lower_block
self.lower_inst(inst)
File "/home/antoine/numba/numba/lowering.py", line 215, in lower_inst
val = self.lower_assign(ty, inst)
File "/home/antoine/numba/numba/lowering.py", line 371, in lower_assign
return self.lower_expr(ty, value)
File "/home/antoine/numba/numba/lowering.py", line 733, in lower_expr
return self.context.build_list(self.builder, resty, castvals)
File "/home/antoine/numba/numba/targets/cpu.py", line 111, in build_list
return listobj.build_list(self, builder, list_type, items)
File "/home/antoine/numba/numba/targets/listobj.py", line 301, in build_list
inst = ListInstance.allocate(context, builder, list_type, nitems)
File "/home/antoine/numba/numba/targets/listobj.py", line 190, in allocate
self._payload.allocated = nitems
File "/home/antoine/numba/numba/targets/listobj.py", line 154, in _payload
return get_list_payload(self._context, self._builder, self._ty, self._list)
File "/home/antoine/numba/numba/targets/listobj.py", line 44, in get_list_payload
return make_payload_cls(list_type)(context, builder, ref=payload)
File "/home/antoine/numba/numba/cgutils.py", line 95, in __init__
% (self._be_type.as_pointer(), ref.type))
AssertionError: bad ref type: expected {i64, i64, i1}*, got {i64, i64, i8}*

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/antoine/numba/numba/dispatcher.py", line 162, in _compile_for_args
return self.compile(sig)
File "/home/antoine/numba/numba/dispatcher.py", line 327, in compile
flags=flags, locals=self.locals)
File "/home/antoine/numba/numba/compiler.py", line 594, in compile_extra
return pipeline.compile_extra(func)
File "/home/antoine/numba/numba/compiler.py", line 317, in compile_extra
return self.compile_bytecode(bc, func_attr=self.func_attr)
File "/home/antoine/numba/numba/compiler.py", line 326, in compile_bytecode
return self._compile_bytecode()
File "/home/antoine/numba/numba/compiler.py", line 581, in _compile_bytecode
return pm.run(self.status)
File "/home/antoine/numba/numba/compiler.py", line 209, in run
raise patched_exception
File "/home/antoine/numba/numba/compiler.py", line 201, in run
res = stage()
File "/home/antoine/numba/numba/compiler.py", line 537, in stage_nopython_backend
return self._backend(lowerfn, objectmode=False)
File "/home/antoine/numba/numba/compiler.py", line 492, in _backend
lowered = lowerfn()
File "/home/antoine/numba/numba/compiler.py", line 483, in backend_nopython_mode
self.flags)
File "/home/antoine/numba/numba/compiler.py", line 723, in native_lowering_stage
lower.lower()
File "/home/antoine/numba/numba/lowering.py", line 100, in lower
self.lower_normal_function(self.fndesc)
File "/home/antoine/numba/numba/lowering.py", line 135, in lower_normal_function
entry_block_tail = self.lower_function_body()
File "/home/antoine/numba/numba/lowering.py", line 160, in lower_function_body
self.lower_block(block)
File "/home/antoine/numba/numba/lowering.py", line 178, in lower_block
raise LoweringError(msg, inst.loc)
numba.errors.LoweringError: Failed at nopython (nopython mode backend)
Internal error:
AssertionError: bad ref type: expected {i64, i64, i1}*, got {i64, i64, i8}*
File "<stdin>", line 1

# Fixed code
def _init_casting_rules(tm):
    tcr = TypeCastingRules(tm)
    tcr.safe_unsafe(types.boolean, types.int8)
    tcr.safe_unsafe(types.boolean, types.uint8)

    tcr.promote_unsafe(types.int8, types.int16)
    tcr.promote_unsafe(types.uint8, types.uint16)

    tcr.promote_unsafe(types.int16, types.int32)
    tcr.promote_unsafe(types.uint16, types.uint32)

    tcr.promote_unsafe(types.int32, types.int64)
    tcr.promote_unsafe(types.uint32, types.uint64)

    tcr.safe_unsafe(types.uint8, types.int16)
    tcr.safe_unsafe(types.uint16, types.int32)
    tcr.safe_unsafe(types.uint32, types.int64)

    tcr.safe_unsafe(types.int16, types.float32)
    tcr.safe_unsafe(types.int32, types.float64)

    tcr.unsafe_unsafe(types.int32, types.float32)
    # XXX this is inconsistent with the above; but we want to prefer
    # float64 over int64 when typing a heterogenous operation,
    # e.g. `float64 + int64`.  Perhaps we need more granularity in the
    # conversion kinds.
    tcr.safe_unsafe(types.int64, types.float64)
    tcr.safe_unsafe(types.uint64, types.float64)

    tcr.promote_unsafe(types.float32, types.float64)

    tcr.safe(types.float32, types.complex64)
    tcr.safe(types.float64, types.complex128)

    tcr.promote_unsafe(types.complex64, types.complex128)

    # Allow integers to cast ot void*
    tcr.unsafe_unsafe(types.uintp, types.voidptr)

    return tcr