# Buggy code
def visit_return_stmt(self, s: ReturnStmt) -> Type:
    """Type check a return statement."""
    self.binder.breaking_out = True
    if self.is_within_function():
        defn = self.function_stack[-1]
        if defn.is_generator:
            return_type = self.get_generator_return_type(
                self.return_types[-1], defn.is_coroutine
            )
        else:
            return_type = self.return_types[-1]

        if s.expr:
            # Return with a value.
            typ = self.accept(s.expr, return_type)
            # Returning a value of type Any is always fine.
            if isinstance(typ, AnyType):
                return None

            if self.is_unusable_type(return_type):
                # Lambdas are allowed to have a unusable returns.
                # Functions returning a value of type None are allowed to have a Void return.
                if isinstance(self.function_stack[-1], FuncExpr) or isinstance(
                    typ, NoneTyp
                ):
                    return None
                self.fail(messages.NO_RETURN_VALUE_EXPECTED, s)
            else:
                self.check_subtype(
                    subtype_label="got",
                    subtype=typ,
                    supertype_label="expected",
                    supertype=return_type,
                    context=s,
                    msg=messages.INCOMPATIBLE_RETURN_VALUE_TYPE,
                )
        else:
            # Empty returns are valid in Generators with Any typed returns.
            if self.function_stack[-1].is_generator and isinstance(
                return_type, AnyType
            ):
                return None

            if isinstance(return_type, (Void, NoneTyp, AnyType)):
                return None

            if self.in_checked_function():
                self.fail(messages.RETURN_VALUE_EXPECTED, s)


# Traceback (AttributeError)
Traceback (most recent call last):
File "./scripts/mypy", line 6, in <module>
main(__file__)
File "mypy/mypy/main.py", line 50, in main
type_check_only(sources, bin_dir, options)
File "mypy/mypy/main.py", line 94, in type_check_only
python_path=options.python_path)
File "mypy/mypy/build.py", line 210, in build
result = manager.process(initial_states)
File "mypy/mypy/build.py", line 425, in process
next.process()
File "mypy/mypy/build.py", line 930, in process
self.type_checker().visit_file(self.tree, self.tree.path)
File "mypy/mypy/checker.py", line 409, in visit_file
self.accept(d)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 707, in accept
return visitor.visit_try_stmt(self)
File "mypy/mypy/checker.py", line 1732, in visit_try_stmt
self.accept(s.else_body)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 526, in accept
return visitor.visit_block(self)
File "mypy/mypy/checker.py", line 1113, in visit_block
self.accept(s)
File "mypy/mypy/checker.py", line 450, in accept
typ = node.accept(self)
File "mypy/mypy/nodes.py", line 382, in accept
return visitor.visit_func_def(self)
File "mypy/mypy/checker.py", line 594, in visit_func_def
'redefinition with type')
File "mypy/mypy/checker.py", line 2117, in check_subtype
if not is_subtype(subtype, supertype):
File "mypy/mypy/subtypes.py", line 49, in is_subtype
return left.accept(SubtypeVisitor(right, type_parameter_checker))
AttributeError: 'NoneType' object has no attribute 'accept'

# Fixed code
def visit_return_stmt(self, s: ReturnStmt) -> Type:
    """Type check a return statement."""
    self.check_return_stmt(s)
    self.binder.unreachable()