# Buggy code
def _run_inliner(
    self,
    state,
    inline_type,
    sig,
    template,
    arg_typs,
    expr,
    i,
    impl,
    block,
    work_list,
    is_method,
):
    from numba.core.inline_closurecall import inline_closure_call, callee_ir_validator

    do_inline = True
    if not inline_type.is_always_inline:
        from numba.core.typing.templates import _inline_info

        caller_inline_info = _inline_info(
            state.func_ir,
            state.type_annotation.typemap,
            state.type_annotation.calltypes,
            sig,
        )

        # must be a cost-model function, run the function
        iinfo = template._inline_overloads[arg_typs]["iinfo"]
        if inline_type.has_cost_model:
            do_inline = inline_type.value(expr, caller_inline_info, iinfo)
        else:
            assert "unreachable"

    if do_inline:
        if is_method:
            if not self._add_method_self_arg(state, expr):
                return False
        arg_typs = template._inline_overloads[arg_typs]["folded_args"]
        # pass is typed so use the callee globals
        inline_closure_call(
            state.func_ir,
            impl.__globals__,
            block,
            i,
            impl,
            typingctx=state.typingctx,
            arg_typs=arg_typs,
            typemap=state.type_annotation.typemap,
            calltypes=state.type_annotation.calltypes,
            work_list=work_list,
            replace_freevars=False,
            callee_validator=callee_ir_validator,
        )
        return True
    else:
        return False


# Traceback (ValueError)
Traceback (most recent call last):
File "test_inline.py", line 14, in <module>
print(fn())
File "numba\numba\dispatcher.py", line 420, in _compile_for_args
raise e
File "numba\numba\dispatcher.py", line 353, in _compile_for_args
return self.compile(tuple(argtypes))
File "numba\numba\compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "numba\numba\dispatcher.py", line 768, in compile
cres = self._compiler.compile(args, return_type)
File "numba\numba\dispatcher.py", line 77, in compile
status, retval = self._compile_cached(args, return_type)
File "numba\numba\dispatcher.py", line 91, in _compile_cached
retval = self._compile_core(args, return_type)
File "numba\numba\dispatcher.py", line 109, in _compile_core
pipeline_class=self.pipeline_class)
File "numba\numba\compiler.py", line 551, in compile_extra
return pipeline.compile_extra(func)
File "numba\numba\compiler.py", line 331, in compile_extra
return self._compile_bytecode()
File "numba\numba\compiler.py", line 393, in _compile_bytecode
return self._compile_core()
File "numba\numba\compiler.py", line 373, in _compile_core
raise e
File "numba\numba\compiler.py", line 364, in _compile_core
pm.run(self.state)
File "numba\numba\compiler_machinery.py", line 347, in run
raise patched_exception
File "numba\numba\compiler_machinery.py", line 338, in run
self._runPass(idx, pass_inst, state)
File "numba\numba\compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "numba\numba\compiler_machinery.py", line 302, in _runPass
mutated |= check(pss.run_pass, internal_state)
File "numba\numba\compiler_machinery.py", line 275, in check
mangled = func(compiler_state)
File "numba\numba\untyped_passes.py", line 312, in run_pass
state.func_ir.blocks = simplify_CFG(state.func_ir.blocks)
File "numba\numba\ir_utils.py", line 1237, in simplify_CFG
return rename_labels(blocks)
File "numba\numba\ir_utils.py", line 1188, in rename_labels
topo_order.remove(return_label)
ValueError: Failed in nopython mode pipeline (step: inline inlinable functions)
list.remove(x): x not in list

# Fixed code
def _run_inliner(
    self,
    state,
    inline_type,
    sig,
    template,
    arg_typs,
    expr,
    i,
    impl,
    block,
    work_list,
    is_method,
    inline_worker,
):
    do_inline = True
    if not inline_type.is_always_inline:
        from numba.core.typing.templates import _inline_info

        caller_inline_info = _inline_info(
            state.func_ir,
            state.type_annotation.typemap,
            state.type_annotation.calltypes,
            sig,
        )

        # must be a cost-model function, run the function
        iinfo = template._inline_overloads[arg_typs]["iinfo"]
        if inline_type.has_cost_model:
            do_inline = inline_type.value(expr, caller_inline_info, iinfo)
        else:
            assert "unreachable"

    if do_inline:
        if is_method:
            if not self._add_method_self_arg(state, expr):
                return False
        arg_typs = template._inline_overloads[arg_typs]["folded_args"]
        iinfo = template._inline_overloads[arg_typs]["iinfo"]
        freevars = iinfo.func_ir.func_id.func.__code__.co_freevars
        _, _, _, new_blocks = inline_worker.inline_ir(
            state.func_ir, block, i, iinfo.func_ir, freevars, arg_typs=arg_typs
        )
        if work_list is not None:
            for blk in new_blocks:
                work_list.append(blk)
        return True
    else:
        return False