Skip to content

Crash if class name is misspelled in match statement #12416

@JukkaL

Description

@JukkaL

This code causes a crash in mypy:

o: object
match o:
    case xyz():
        pass

Traceback:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/jukka/src/mypy/mypy/__main__.py", line 34, in <module>
    console_entry()
  File "/Users/jukka/src/mypy/mypy/__main__.py", line 12, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "/Users/jukka/src/mypy/mypy/main.py", line 96, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/Users/jukka/src/mypy/mypy/main.py", line 173, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/Users/jukka/src/mypy/mypy/build.py", line 180, in build
    result = _build(
  File "/Users/jukka/src/mypy/mypy/build.py", line 256, in _build
    graph = dispatch(sources, manager, stdout)
  File "/Users/jukka/src/mypy/mypy/build.py", line 2733, in dispatch
    process_graph(graph, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 3077, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/jukka/src/mypy/mypy/build.py", line 3175, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/Users/jukka/src/mypy/mypy/build.py", line 2192, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/Users/jukka/src/mypy/mypy/checker.py", line 318, in check_first_pass
    self.accept(d)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 424, in accept
    stmt.accept(self)
  File "/Users/jukka/src/mypy/mypy/nodes.py", line 1403, in accept
    return visitor.visit_match_stmt(self)
  File "/Users/jukka/src/mypy/mypy/checker.py", line 4121, in visit_match_stmt
    pattern_types = [self.pattern_checker.accept(p, subject_type) for p in s.patterns]
  File "/Users/jukka/src/mypy/mypy/checker.py", line 4121, in <listcomp>
    pattern_types = [self.pattern_checker.accept(p, subject_type) for p in s.patterns]
  File "/Users/jukka/src/mypy/mypy/checkpattern.py", line 107, in accept
    result = o.accept(self)
  File "/Users/jukka/src/mypy/mypy/patterns.py", line 137, in accept
    return visitor.visit_class_pattern(self)
  File "/Users/jukka/src/mypy/mypy/checkpattern.py", line 466, in visit_class_pattern
    assert type_info is not None
AssertionError:

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions