@@ -529,7 +529,7 @@ def check_first_pass(self) -> None:
529529self .msg .unreachable_statement (d )
530530break
531531else :
532- self .accept (d )
532+ self .accept_with_delayed_errors (d )
533533
534534assert not self .current_node_deferred
535535
@@ -637,14 +637,17 @@ def handle_cannot_determine_type(self, name: str, context: Context) -> None:
637637else :
638638self .msg .cannot_determine_type (name ,context )
639639
640- def accept (self ,stmt :Statement )-> None :
641- """Type check a node in the given type context."""
640+ def accept_with_delayed_errors (self ,stmt :Statement )-> None :
642641curr_module = self .scope .stack [0 ]
643642if isinstance (curr_module ,MypyFile ):
644643key = (curr_module .fullname ,stmt .line ,stmt .column )
645644if key in self .semanal_delayed_errors :
646645self .msg .add_errors (self .semanal_delayed_errors [key ])
647646
647+ self .accept (stmt )
648+
649+ def accept (self ,stmt :Statement )-> None :
650+ """Type check a node in the given type context."""
648651try :
649652stmt .accept (self )
650653except Exception as err :
@@ -1235,16 +1238,6 @@ def check_func_item(
12351238 """
12361239self .dynamic_funcs .append (defn .is_dynamic ()and not type_override )
12371240
1238- # top-level function definitions are one of the main
1239- # things errors can be associated with, and are sometimes masked
1240- # e.g. by a decorator. it's better to make sure to flush any errors
1241- # just in case.
1242- curr_module = self .scope .stack [0 ]
1243- if isinstance (curr_module ,MypyFile ):
1244- key = (curr_module .fullname ,defn .line ,defn .column )
1245- if key in self .semanal_delayed_errors :
1246- self .msg .add_errors (self .semanal_delayed_errors [key ])
1247-
12481241enclosing_node_deferred = self .current_node_deferred
12491242with self .enter_partial_types (is_function = True ):
12501243typ = self .function_type (defn )
@@ -3174,7 +3167,7 @@ def visit_block(self, b: Block) -> None:
31743167self .msg .unreachable_statement (s )
31753168break
31763169else :
3177- self .accept (s )
3170+ self .accept_with_delayed_errors (s )
31783171# Clear expression cache after each statement to avoid unlimited growth.
31793172self .expr_checker .expr_cache .clear ()
31803173