# Buggy code
def visit_instance(self, t: Instance) -> ProperType:
    if isinstance(self.s, Instance):
        si = self.s
        if t.type == si.type:
            if is_subtype(t, self.s) or is_subtype(self.s, t):
                # Combine type arguments. We could have used join below
                # equivalently.
                args = []  # type: List[Type]
                for i in range(len(t.args)):
                    args.append(self.meet(t.args[i], si.args[i]))
                return Instance(t.type, args)
            else:
                if state.strict_optional:
                    return UninhabitedType()
                else:
                    return NoneType()
        else:
            if is_subtype(t, self.s):
                return t
            elif is_subtype(self.s, t):
                # See also above comment.
                return self.s
            else:
                if state.strict_optional:
                    return UninhabitedType()
                else:
                    return NoneType()
    elif isinstance(self.s, FunctionLike) and t.type.is_protocol:
        call = unpack_callback_protocol(t)
        if call:
            return meet_types(call, self.s)
    elif (
        isinstance(self.s, FunctionLike)
        and self.s.is_type_obj()
        and t.type.is_metaclass()
    ):
        if is_subtype(self.s.fallback, t):
            return self.s
        return self.default(self.s)
    elif isinstance(self.s, TypeType):
        return meet_types(t, self.s)
    elif isinstance(self.s, TupleType):
        return meet_types(t, self.s)
    elif isinstance(self.s, LiteralType):
        return meet_types(t, self.s)
    elif isinstance(self.s, TypedDictType):
        return meet_types(t, self.s)
    return self.default(self.s)


# Traceback (IndexError)
$ mypy --quick --show-traceback a.py
b.py:7: error: Revealed type is 'def () -> b.C'
/Users/jukka/src/mypy/b.py:11: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.510-dev-c856a53fe06c0ad9193d86ab35fb86693940f273-dirty
Traceback (most recent call last):
File "/Users/jukka/src/mypy/scripts/mypy", line 6, in <module>
main(__file__)
File "/Users/jukka/src/mypy/mypy/main.py", line 46, in main
res = type_check_only(sources, bin_dir, options)
File "/Users/jukka/src/mypy/mypy/main.py", line 93, in type_check_only
options=options)
File "/Users/jukka/src/mypy/mypy/build.py", line 188, in build
graph = dispatch(sources, manager)
File "/Users/jukka/src/mypy/mypy/build.py", line 1570, in dispatch
process_graph(graph, manager)
File "/Users/jukka/src/mypy/mypy/build.py", line 1813, in process_graph
process_stale_scc(graph, scc, manager)
File "/Users/jukka/src/mypy/mypy/build.py", line 1912, in process_stale_scc
graph[id].type_check_first_pass()
File "/Users/jukka/src/mypy/mypy/build.py", line 1485, in type_check_first_pass
self.type_checker.check_first_pass()
File "/Users/jukka/src/mypy/mypy/checker.py", line 177, in check_first_pass
self.accept(d)
File "/Users/jukka/src/mypy/mypy/checker.py", line 262, in accept
stmt.accept(self)
File "/Users/jukka/src/mypy/mypy/nodes.py", line 853, in accept
return visitor.visit_assignment_stmt(self)
File "/Users/jukka/src/mypy/mypy/checker.py", line 1177, in visit_assignment_stmt
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
File "/Users/jukka/src/mypy/mypy/checker.py", line 1239, in check_assignment
rvalue_type = self.check_simple_assignment(lvalue_type, rvalue, lvalue)
File "/Users/jukka/src/mypy/mypy/checker.py", line 1698, in check_simple_assignment
rvalue_type = self.expr_checker.accept(rvalue, lvalue_type)
File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 2056, in accept
typ = node.accept(self)
File "/Users/jukka/src/mypy/mypy/nodes.py", line 1213, in accept
return visitor.visit_name_expr(self)
File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 123, in visit_name_expr
return self.narrow_type_from_binder(e, result)
File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 2271, in narrow_type_from_binder
ans = narrow_declared_type(known_type, restriction)
File "/Users/jukka/src/mypy/mypy/meet.py", line 46, in narrow_declared_type
return meet_types(declared, narrowed)
File "/Users/jukka/src/mypy/mypy/meet.py", line 25, in meet_types
return t.accept(TypeMeetVisitor(s))
File "/Users/jukka/src/mypy/mypy/types.py", line 381, in accept
return visitor.visit_instance(self)
File "/Users/jukka/src/mypy/mypy/meet.py", line 198, in visit_instance
args.append(self.meet(t.args[i], si.args[i]))
IndexError: list index out of range
/Users/jukka/src/mypy/b.py:11: note: use --pdb to drop into pdb

# Fixed code
def visit_instance(self, t: Instance) -> ProperType:
    if isinstance(self.s, Instance):
        si = self.s
        if t.type == si.type:
            if is_subtype(t, self.s) or is_subtype(self.s, t):
                # Combine type arguments. We could have used join below
                # equivalently.
                args = []  # type: List[Type]
                # N.B: We use zip instead of indexing because the lengths might have
                # mismatches during daemon reprocessing.
                for ta, sia in zip(t.args, si.args):
                    args.append(self.meet(ta, sia))
                return Instance(t.type, args)
            else:
                if state.strict_optional:
                    return UninhabitedType()
                else:
                    return NoneType()
        else:
            if is_subtype(t, self.s):
                return t
            elif is_subtype(self.s, t):
                # See also above comment.
                return self.s
            else:
                if state.strict_optional:
                    return UninhabitedType()
                else:
                    return NoneType()
    elif isinstance(self.s, FunctionLike) and t.type.is_protocol:
        call = unpack_callback_protocol(t)
        if call:
            return meet_types(call, self.s)
    elif (
        isinstance(self.s, FunctionLike)
        and self.s.is_type_obj()
        and t.type.is_metaclass()
    ):
        if is_subtype(self.s.fallback, t):
            return self.s
        return self.default(self.s)
    elif isinstance(self.s, TypeType):
        return meet_types(t, self.s)
    elif isinstance(self.s, TupleType):
        return meet_types(t, self.s)
    elif isinstance(self.s, LiteralType):
        return meet_types(t, self.s)
    elif isinstance(self.s, TypedDictType):
        return meet_types(t, self.s)
    return self.default(self.s)