diff --git a/mypy/newsemanal/semanal_main.py b/mypy/newsemanal/semanal_main.py index 874670192628..f9699df21d2a 100644 --- a/mypy/newsemanal/semanal_main.py +++ b/mypy/newsemanal/semanal_main.py @@ -225,7 +225,10 @@ def process_top_level_function(analyzer: 'NewSemanticAnalyzer', while deferred: iteration += 1 if iteration == MAX_ITERATIONS: - analyzer.report_hang() + # Just pick some module inside the current SCC for error context. + assert state.tree is not None + with analyzer.file_context(state.tree, state.tree.path, state.options): + analyzer.report_hang() break if not (deferred or incomplete) or final_iteration: # OK, this is one last pass, now missing names will be reported. diff --git a/test-data/unit/check-newsemanal.test b/test-data/unit/check-newsemanal.test index 6b7a19da60e4..9853ebb88b12 100644 --- a/test-data/unit/check-newsemanal.test +++ b/test-data/unit/check-newsemanal.test @@ -2243,3 +2243,9 @@ force1(reveal_type(var1)) # E: Revealed type is 'Literal[1]' class A(A): ... [out] main: error: Internal error: maximum semantic analysis iteration count reached + +[case testNewAnalyzerReportLoopInMRO2] +def f() -> None: + class A(A): ... +[out] +main: error: Internal error: maximum semantic analysis iteration count reached