Skip to content

Fix reporting of likely hangs in the new semantic analyzer #6872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/newsemanal/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def adjust_public_exports(self) -> None:

@contextmanager
def file_context(self, file_node: MypyFile, fnam: str, options: Options,
active_type: Optional[TypeInfo],
active_type: Optional[TypeInfo] = None,
scope: Optional[Scope] = None) -> Iterator[None]:
# TODO: Use this above in visit_file
scope = scope or self.scope
Expand Down
6 changes: 5 additions & 1 deletion mypy/newsemanal/semanal_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ def process_top_levels(graph: 'Graph', scc: List[str], patches: Patches) -> None
while worklist:
iteration += 1
if iteration > MAX_ITERATIONS:
state.manager.new_semantic_analyzer.report_hang()
analyzer = state.manager.new_semantic_analyzer
# 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 final_iteration:
# Give up. It's impossible to bind all names.
Expand Down
5 changes: 5 additions & 0 deletions test-data/unit/check-newsemanal.test
Original file line number Diff line number Diff line change
Expand Up @@ -2238,3 +2238,8 @@ var1: Final = 1
def force1(x: Literal[1]) -> None: pass

force1(reveal_type(var1)) # E: Revealed type is 'Literal[1]'

[case testNewAnalyzerReportLoopInMRO]
class A(A): ...
[out]
main: error: Internal error: maximum semantic analysis iteration count reached