diff --git a/mypy/newsemanal/semanal.py b/mypy/newsemanal/semanal.py index 5b8173e346ac..18a154fc4781 100644 --- a/mypy/newsemanal/semanal.py +++ b/mypy/newsemanal/semanal.py @@ -541,7 +541,11 @@ def _visit_func_def(self, defn: FuncDef) -> None: # Signature must be analyzed in the surrounding scope so that # class-level imported names and type variables are in scope. analyzer = self.type_analyzer() - defn.type = analyzer.visit_callable_type(defn.type, nested=False) + tag = self.track_incomplete_refs() + result = analyzer.visit_callable_type(defn.type, nested=False) + if self.found_incomplete_ref(tag): + return + defn.type = result self.add_type_alias_deps(analyzer.aliases_used) self.check_function_signature(defn) if isinstance(defn, FuncDef): diff --git a/test-data/unit/check-newsemanal.test b/test-data/unit/check-newsemanal.test index 73cf027c1171..f1be3c9cfa59 100644 --- a/test-data/unit/check-newsemanal.test +++ b/test-data/unit/check-newsemanal.test @@ -1702,3 +1702,7 @@ from typing import Tuple c: C class C(Tuple[int, str]): def __init__(self) -> None: pass + +[case testNewAnalyzerFunctionError] +def f(x: asdf) -> None: # E: Name 'asdf' is not defined + pass