# Buggy code
def infer_arg_types_in_context(
    self, callee: CallableType, args: List[Node]
) -> List[Type]:
    """Infer argument expression types using a callable type as context.

    For example, if callee argument 2 has type List[int], infer the
    argument expression with List[int] type context.
    """
    # TODO Always called with callee as None, i.e. empty context.
    res = []  # type: List[Type]

    fixed = len(args)
    if callee:
        fixed = min(fixed, callee.max_fixed_args())

    arg_type = None  # type: Type
    ctx = None  # type: Type
    for i, arg in enumerate(args):
        if i < fixed:
            if callee and i < len(callee.arg_types):
                ctx = callee.arg_types[i]
            arg_type = self.accept(arg, ctx)
        else:
            if callee and callee.is_var_arg:
                arg_type = self.accept(arg, callee.arg_types[-1])
            else:
                arg_type = self.accept(arg)
        if isinstance(arg_type, ErasedType):
            res.append(NoneTyp())
        else:
            res.append(arg_type)
    return res


# Traceback (RuntimeError)
Traceback (most recent call last):
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/bin/.mypy-wrapped", line 7, in <module>
main(__file__)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/main.py", line 54, in main
res = type_check_only(sources, bin_dir, options)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/main.py", line 102, in type_check_only
python_path=options.python_path)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/build.py", line 209, in build
dispatch(sources, manager)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/build.py", line 1255, in dispatch
process_graph(graph, manager)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/build.py", line 1386, in process_graph
process_stale_scc(graph, scc)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/build.py", line 1416, in process_stale_scc
graph[id].type_check()
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/build.py", line 1235, in type_check
manager.type_checker.visit_file(self.tree, self.xpath)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/checker.py", line 419, in visit_file
self.accept(d)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/checker.py", line 460, in accept
typ = node.accept(self)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/nodes.py", line 462, in accept
return visitor.visit_func_def(self)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/checker.py", line 573, in visit_func_def
self.check_func_item(defn, name=defn.name())
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/checker.py", line 631, in check_func_item
self.check_func_def(defn, typ, name)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/checker.py", line 739, in check_func_def
self.accept_in_frame(item.body)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/checker.py", line 475, in accept_in_frame
answer = self.accept(node, type_context)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/checker.py", line 460, in accept
typ = node.accept(self)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/nodes.py", line 715, in accept
return visitor.visit_block(self)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/checker.py", line 1132, in visit_block
self.accept(s)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/checker.py", line 460, in accept
typ = node.accept(self)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/nodes.py", line 753, in accept
return visitor.visit_assignment_stmt(self)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/checker.py", line 1141, in visit_assignment_stmt
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/checker.py", line 1192, in check_assignment
rvalue)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/checker.py", line 1424, in infer_variable_type
elif not is_valid_inferred_type(init_type):
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/checker.py", line 2549, in is_valid_inferred_type
if not is_valid_inferred_type(item):
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/checker.py", line 2541, in is_valid_inferred_type
if is_same_type(typ, NoneTyp()):
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/sametypes.py", line 27, in is_same_type
return left.accept(SameTypeVisitor(right))
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/types.py", line 244, in accept
return visitor.visit_erased_type(self)
File "/nix/store/czly6jrafckfvwm9mjc6wvandc2ddwi9-python3.5-mypy-lang-0.4.1/lib/python3.5/site-packages/mypy/sametypes.py", line 74, in visit_erased_type
raise RuntimeError()
RuntimeError:

*** INTERNAL ERROR ***

# Fixed code
def infer_arg_types_in_context(
    self, callee: CallableType, args: List[Node]
) -> List[Type]:
    """Infer argument expression types using a callable type as context.

    For example, if callee argument 2 has type List[int], infer the
    argument expression with List[int] type context.
    """
    # TODO Always called with callee as None, i.e. empty context.
    res = []  # type: List[Type]

    fixed = len(args)
    if callee:
        fixed = min(fixed, callee.max_fixed_args())

    arg_type = None  # type: Type
    ctx = None  # type: Type
    for i, arg in enumerate(args):
        if i < fixed:
            if callee and i < len(callee.arg_types):
                ctx = callee.arg_types[i]
            arg_type = self.accept(arg, ctx)
        else:
            if callee and callee.is_var_arg:
                arg_type = self.accept(arg, callee.arg_types[-1])
            else:
                arg_type = self.accept(arg)
        if has_erased_component(arg_type):
            res.append(NoneTyp())
        else:
            res.append(arg_type)
    return res