# Buggy code
def _do_work_call(self, state, work_list, block, i, expr):
    # try and get a definition for the call, this isn't always possible as
    # it might be a eval(str)/part generated awaiting update etc. (parfors)
    to_inline = None
    try:
        to_inline = state.func_ir.get_definition(expr.func)
    except Exception:
        return False

    # do not handle closure inlining here, another pass deals with that.
    if getattr(to_inline, "op", False) == "make_function":
        return False

    # check this is a known and typed function
    try:
        func_ty = state.type_annotation.typemap[expr.func.name]
    except KeyError:
        # e.g. Calls to CUDA Intrinsic have no mapped type so KeyError
        return False
    if not hasattr(func_ty, "get_call_type"):
        return False

    sig = state.type_annotation.calltypes[expr]
    is_method = False

    # search the templates for this overload looking for "inline"
    if getattr(func_ty, "template", None) is not None:
        # @overload_method
        is_method = True
        templates = [func_ty.template]
        arg_typs = (func_ty.template.this,) + sig.args
    else:
        # @overload case
        templates = getattr(func_ty, "templates", None)
        arg_typs = sig.args

    if templates is None:
        return False

    impl = None
    for template in templates:
        inline_type = getattr(template, "_inline", None)
        if inline_type is None:
            # inline not defined
            continue
        if not inline_type.is_never_inline:
            try:
                impl = template._overload_func(*arg_typs)
                if impl is None:
                    raise Exception  # abort for this template
                break
            except Exception:
                continue
    else:
        return False

    # at this point we know we maybe want to inline something and there's
    # definitely something that could be inlined.
    return self._run_inliner(
        state,
        inline_type,
        sig,
        template,
        arg_typs,
        expr,
        i,
        impl,
        block,
        work_list,
        is_method,
    )


# 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 _do_work_call(self, state, work_list, block, i, expr, inline_worker):
    # try and get a definition for the call, this isn't always possible as
    # it might be a eval(str)/part generated awaiting update etc. (parfors)
    to_inline = None
    try:
        to_inline = state.func_ir.get_definition(expr.func)
    except Exception:
        return False

    # do not handle closure inlining here, another pass deals with that.
    if getattr(to_inline, "op", False) == "make_function":
        return False

    # check this is a known and typed function
    try:
        func_ty = state.type_annotation.typemap[expr.func.name]
    except KeyError:
        # e.g. Calls to CUDA Intrinsic have no mapped type so KeyError
        return False
    if not hasattr(func_ty, "get_call_type"):
        return False

    sig = state.type_annotation.calltypes[expr]
    is_method = False

    # search the templates for this overload looking for "inline"
    if getattr(func_ty, "template", None) is not None:
        # @overload_method
        is_method = True
        templates = [func_ty.template]
        arg_typs = (func_ty.template.this,) + sig.args
    else:
        # @overload case
        templates = getattr(func_ty, "templates", None)
        arg_typs = sig.args

    if templates is None:
        return False

    impl = None
    for template in templates:
        inline_type = getattr(template, "_inline", None)
        if inline_type is None:
            # inline not defined
            continue
        if not inline_type.is_never_inline:
            try:
                impl = template._overload_func(*arg_typs)
                if impl is None:
                    raise Exception  # abort for this template
                break
            except Exception:
                continue
    else:
        return False

    # at this point we know we maybe want to inline something and there's
    # definitely something that could be inlined.
    return self._run_inliner(
        state,
        inline_type,
        sig,
        template,
        arg_typs,
        expr,
        i,
        impl,
        block,
        work_list,
        is_method,
        inline_worker,
    )