# Buggy code
def run_pass(self, state):
    """Run inlining of inlinables"""
    if self._DEBUG:
        print("before inline".center(80, "-"))
        print(state.func_ir.dump())
        print("".center(80, "-"))
    modified = False
    # use a work list, look for call sites via `ir.Expr.op == call` and
    # then pass these to `self._do_work` to make decisions about inlining.
    work_list = list(state.func_ir.blocks.items())
    while work_list:
        label, block = work_list.pop()
        for i, instr in enumerate(block.body):
            if isinstance(instr, ir.Assign):
                expr = instr.value
                if isinstance(expr, ir.Expr) and expr.op == "call":
                    if guard(self._do_work, state, work_list, block, i, expr):
                        modified = True
                        break  # because block structure changed

    if modified:
        # clean up unconditional branches that appear due to inlined
        # functions introducing blocks
        state.func_ir.blocks = simplify_CFG(state.func_ir.blocks)

    if self._DEBUG:
        print("after inline".center(80, "-"))
        print(state.func_ir.dump())
        print("".center(80, "-"))
    return True


# 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_pass(self, state):
    """Run inlining of inlinables"""
    if self._DEBUG:
        print("before inline".center(80, "-"))
        print(state.func_ir.dump())
        print("".center(80, "-"))

    from numba.core.inline_closurecall import InlineWorker, callee_ir_validator

    inline_worker = InlineWorker(
        state.typingctx,
        state.targetctx,
        state.locals,
        state.pipeline,
        state.flags,
        validator=callee_ir_validator,
    )

    modified = False
    # use a work list, look for call sites via `ir.Expr.op == call` and
    # then pass these to `self._do_work` to make decisions about inlining.
    work_list = list(state.func_ir.blocks.items())
    while work_list:
        label, block = work_list.pop()
        for i, instr in enumerate(block.body):
            if isinstance(instr, ir.Assign):
                expr = instr.value
                if isinstance(expr, ir.Expr) and expr.op == "call":
                    if guard(
                        self._do_work, state, work_list, block, i, expr, inline_worker
                    ):
                        modified = True
                        break  # because block structure changed

    if modified:
        # clean up unconditional branches that appear due to inlined
        # functions introducing blocks
        cfg = compute_cfg_from_blocks(state.func_ir.blocks)
        for dead in cfg.dead_nodes():
            del state.func_ir.blocks[dead]
        post_proc = postproc.PostProcessor(state.func_ir)
        post_proc.run()
        state.func_ir.blocks = simplify_CFG(state.func_ir.blocks)

    if self._DEBUG:
        print("after inline".center(80, "-"))
        print(state.func_ir.dump())
        print("".center(80, "-"))
    return True