# Buggy code
def run(self):
    """Run inline closure call pass."""
    modified = False
    work_list = list(self.func_ir.blocks.items())
    _debug_print("START InlineClosureCall")
    while work_list:
        label, block = work_list.pop()
        for i in range(len(block.body)):
            instr = block.body[i]
            if isinstance(instr, ir.Assign):
                lhs = instr.target
                expr = instr.value
                if isinstance(expr, ir.Expr) and expr.op == "call":
                    try:
                        func_def = self.func_ir.get_definition(expr.func)
                    except KeyError:
                        func_def = None
                    _debug_print("found call to ", expr.func, " def = ", func_def)
                    if isinstance(func_def, ir.Expr) and func_def.op == "make_function":
                        new_blocks = self.inline_closure_call(block, i, func_def)
                        for block in new_blocks:
                            work_list.append(block)
                        modified = True
                        # current block is modified, skip the rest
                        break
    if modified:
        remove_dels(self.func_ir.blocks)
        # repeat dead code elimintation until nothing can be further removed
        while remove_dead(self.func_ir.blocks, self.func_ir.arg_names):
            pass
        self.func_ir.blocks = rename_labels(self.func_ir.blocks)


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-3b23f7331ceb> in <module>()
----> 1 @jit(arg_types=[numba.double], ret_type=numba.double)
2 def is_REALLY_five(some_value):
3     for i in range(5):
4         if some_value == 5.0:
5             return 1.0

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/decorators.pyc in _jit(func)
77                   "garbage collected!" % (func,))
78         t = Translate(func, *args, **kws)
---> 79         t.translate()
80         __tr_map__[func] = t
81         return t.get_ctypes_func(llvm)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in translate(self)
926                     # Ensure we are playing with locals that might
927                     # actually precede the next block.
--> 928                     self.check_locals(i)
929
930                 self.crnt_block = i

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/numba/translate.pyc in check_locals(self, i)
1135                 else:
1136                     assert next_locals is not None, "Internal compiler error!"
-> 1137             self._locals = next_locals[:]
1138
1139     def get_ctypes_func(self, llvm=True):

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def run(self):
    """Run inline closure call pass."""
    modified = False
    work_list = list(self.func_ir.blocks.items())
    debug_print = _make_debug_print("InlineClosureCallPass")
    debug_print("START")
    while work_list:
        label, block = work_list.pop()
        for i in range(len(block.body)):
            instr = block.body[i]
            if isinstance(instr, ir.Assign):
                lhs = instr.target
                expr = instr.value
                if isinstance(expr, ir.Expr) and expr.op == "call":
                    func_def = guard(_get_definition, self.func_ir, expr.func)
                    debug_print("found call to ", expr.func, " def = ", func_def)
                    if isinstance(func_def, ir.Expr) and func_def.op == "make_function":
                        new_blocks = self.inline_closure_call(block, i, func_def)
                        for block in new_blocks:
                            work_list.append(block)
                        modified = True
                        # current block is modified, skip the rest
                        break

    if enable_inline_arraycall:
        # Identify loop structure
        if modified:
            # Need to do some cleanups if closure inlining kicked in
            merge_adjacent_blocks(self.func_ir)
        cfg = compute_cfg_from_blocks(self.func_ir.blocks)
        debug_print("start inline arraycall")
        _debug_dump(cfg)
        loops = cfg.loops()
        sized_loops = [(k, len(loops[k].body)) for k in loops.keys()]
        visited = []
        # We go over all loops, bigger loops first (outer first)
        for k, s in sorted(sized_loops, key=lambda tup: tup[1], reverse=True):
            visited.append(k)
            if guard(
                _inline_arraycall,
                self.func_ir,
                cfg,
                visited,
                loops[k],
                self.flags.auto_parallel,
            ):
                modified = True
        if modified:
            _fix_nested_array(self.func_ir)

    if modified:
        remove_dels(self.func_ir.blocks)
        # repeat dead code elimintation until nothing can be further
        # removed
        while remove_dead(self.func_ir.blocks, self.func_ir.arg_names):
            pass
        self.func_ir.blocks = rename_labels(self.func_ir.blocks)
    debug_print("END")