Skip to content

Commit d24e9e8

Browse files
authored
Fix hang reporting more (follow-up to #6872) (#6875)
Fix another crash related to hitting max iteration count in the new semantic analyzer.
1 parent debb1e5 commit d24e9e8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

mypy/newsemanal/semanal_main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,10 @@ def process_top_level_function(analyzer: 'NewSemanticAnalyzer',
225225
while deferred:
226226
iteration += 1
227227
if iteration == MAX_ITERATIONS:
228-
analyzer.report_hang()
228+
# Just pick some module inside the current SCC for error context.
229+
assert state.tree is not None
230+
with analyzer.file_context(state.tree, state.tree.path, state.options):
231+
analyzer.report_hang()
229232
break
230233
if not (deferred or incomplete) or final_iteration:
231234
# OK, this is one last pass, now missing names will be reported.

test-data/unit/check-newsemanal.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,3 +2243,9 @@ force1(reveal_type(var1)) # E: Revealed type is 'Literal[1]'
22432243
class A(A): ...
22442244
[out]
22452245
main: error: Internal error: maximum semantic analysis iteration count reached
2246+
2247+
[case testNewAnalyzerReportLoopInMRO2]
2248+
def f() -> None:
2249+
class A(A): ...
2250+
[out]
2251+
main: error: Internal error: maximum semantic analysis iteration count reached

0 commit comments

Comments
 (0)