# Buggy code
def define_nopython_pipeline(state, name="nopython"):
    """Returns an nopython mode pipeline based PassManager"""
    pm = PassManager(name)
    if state.func_ir is None:
        pm.add_pass(TranslateByteCode, "analyzing bytecode")
        pm.add_pass(FixupArgs, "fix up args")
    pm.add_pass(IRProcessing, "processing IR")
    pm.add_pass(WithLifting, "Handle with contexts")

    # pre typing
    if not state.flags.no_rewrites:
        pm.add_pass(RewriteSemanticConstants, "rewrite semantic constants")
        pm.add_pass(DeadBranchPrune, "dead branch pruning")
        pm.add_pass(GenericRewrites, "nopython rewrites")

    pm.add_pass(InlineClosureLikes, "inline calls to locally defined closures")
    # convert any remaining closures into functions
    pm.add_pass(MakeFunctionToJitFunction, "convert make_function into JIT functions")
    # inline functions that have been determined as inlinable and rerun
    # branch pruning, this needs to be run after closures are inlined as
    # the IR repr of a closure masks call sites if an inlinable is called
    # inside a closure
    pm.add_pass(InlineInlinables, "inline inlinable functions")
    if not state.flags.no_rewrites:
        pm.add_pass(DeadBranchPrune, "dead branch pruning")

    pm.add_pass(FindLiterallyCalls, "find literally calls")
    pm.add_pass(LiteralUnroll, "handles literal_unroll")

    if state.flags.enable_ssa:
        pm.add_pass(ReconstructSSA, "ssa")
    # typing
    pm.add_pass(NopythonTypeInference, "nopython frontend")
    pm.add_pass(AnnotateTypes, "annotate types")

    # strip phis
    pm.add_pass(PreLowerStripPhis, "remove phis nodes")

    # optimisation
    pm.add_pass(InlineOverloads, "inline overloaded functions")
    if state.flags.auto_parallel.enabled:
        pm.add_pass(PreParforPass, "Preprocessing for parfors")
    if not state.flags.no_rewrites:
        pm.add_pass(NopythonRewrites, "nopython rewrites")
    if state.flags.auto_parallel.enabled:
        pm.add_pass(ParforPass, "convert to parfors")

    # legalise
    pm.add_pass(IRLegalization, "ensure IR is legal prior to lowering")

    # lower
    pm.add_pass(NoPythonBackend, "nopython mode backend")
    pm.add_pass(DumpParforDiagnostics, "dump parfor diagnostics")
    pm.finalize()
    return pm


# 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 define_nopython_pipeline(state, name="nopython"):
    """Returns an nopython mode pipeline based PassManager"""
    # compose pipeline from untyped, typed and lowering parts
    dpb = DefaultPassBuilder
    pm = PassManager(name)
    untyped_passes = dpb.define_untyped_pipeline(state)
    pm.passes.extend(untyped_passes.passes)

    typed_passes = dpb.define_typed_pipeline(state)
    pm.passes.extend(typed_passes.passes)

    lowering_passes = dpb.define_nopython_lowering_pipeline(state)
    pm.passes.extend(lowering_passes.passes)

    pm.finalize()
    return pm