# Buggy code
def visit_lambda_expr(self, e: LambdaExpr) -> Type:
    """Type check lambda expression."""
    inferred_type, type_override = self.infer_lambda_type_using_context(e)
    if not inferred_type:
        # No useful type context.
        ret_type = self.accept(e.expr(), allow_none_return=True)
        fallback = self.named_type("builtins.function")
        return callable_type(e, fallback, ret_type)
    else:
        # Type context available.
        self.chk.check_func_item(e, type_override=type_override)
        if e.expr() not in self.chk.type_map:
            self.accept(e.expr(), allow_none_return=True)
        ret_type = self.chk.type_map[e.expr()]
        if isinstance(ret_type, NoneTyp):
            # For "lambda ...: None", just use type from the context.
            # Important when the context is Callable[..., None] which
            # really means Void. See #1425.
            return inferred_type
        return replace_callable_return_type(inferred_type, ret_type)


# Traceback (IndexError)
error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues
Traceback (most recent call last):
File "/usr/local/bin/mypy", line 6, in <module>
main(__file__)
File "/usr/local/lib/python3.6/site-packages/mypy/main.py", line 42, in main
res = type_check_only(sources, bin_dir, options)
File "/usr/local/lib/python3.6/site-packages/mypy/main.py", line 86, in type_check_only
options=options)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 183, in build
dispatch(sources, manager)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 1531, in dispatch
process_graph(graph, manager)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 1768, in process_graph
process_stale_scc(graph, scc)
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 1847, in process_stale_scc
graph[id].type_check_first_pass()
File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 1453, in type_check_first_pass
self.type_checker.check_first_pass()
File "/usr/local/lib/python3.6/site-packages/mypy/checker.py", line 167, in check_first_pass
self.accept(d)
File "/usr/local/lib/python3.6/site-packages/mypy/checker.py", line 233, in accept
stmt.accept(self)
File "/usr/local/lib/python3.6/site-packages/mypy/nodes.py", line 792, in accept
return visitor.visit_expression_stmt(self)
File "/usr/local/lib/python3.6/site-packages/mypy/checker.py", line 1683, in visit_expression_stmt
self.expr_checker.accept(s.expr)
File "/usr/local/lib/python3.6/site-packages/mypy/checkexpr.py", line 2015, in accept
typ = node.accept(self)
File "/usr/local/lib/python3.6/site-packages/mypy/nodes.py", line 1507, in accept
return visitor.visit_func_expr(self)
File "/usr/local/lib/python3.6/site-packages/mypy/checkexpr.py", line 1769, in visit_func_expr
ret_type = self.accept(e.expr())
File "/usr/local/lib/python3.6/site-packages/mypy/checkexpr.py", line 2015, in accept
typ = node.accept(self)
File "/usr/local/lib/python3.6/site-packages/mypy/nodes.py", line 1284, in accept
return visitor.visit_yield_expr(self)
File "/usr/local/lib/python3.6/site-packages/mypy/checkexpr.py", line 2088, in visit_yield_expr
return_type = self.chk.return_types[-1]
IndexError: list index out of range

# Fixed code
def visit_lambda_expr(self, e: LambdaExpr) -> Type:
    """Type check lambda expression."""
    inferred_type, type_override = self.infer_lambda_type_using_context(e)
    if not inferred_type:
        self.chk.return_types.append(AnyType())
        # No useful type context.
        ret_type = self.accept(e.expr(), allow_none_return=True)
        fallback = self.named_type("builtins.function")
        self.chk.return_types.pop()
        return callable_type(e, fallback, ret_type)
    else:
        # Type context available.
        self.chk.return_types.append(inferred_type.ret_type)
        self.chk.check_func_item(e, type_override=type_override)
        if e.expr() not in self.chk.type_map:
            self.accept(e.expr(), allow_none_return=True)
        ret_type = self.chk.type_map[e.expr()]
        if isinstance(ret_type, NoneTyp):
            # For "lambda ...: None", just use type from the context.
            # Important when the context is Callable[..., None] which
            # really means Void. See #1425.
            self.chk.return_types.pop()
            return inferred_type
        self.chk.return_types.pop()
        return replace_callable_return_type(inferred_type, ret_type)