Skip to content

Crash when serializing property with forward reference #4682

Closed
@JukkaL

Description

@JukkaL

This serialization test case fails with a crash:

[case testSerializeForwardReferenceToAliasInProperty]
import a
[file a.py]
import b
[file a.py.2]
import b
reveal_type(b.A().p)
[file b.py]

class A:
    @property
    def p(self) -> C: pass
    @p.setter
    def p(self, c: C) -> None: pass
    @p.deleter
    def p(self) -> None: pass

C = str
[builtins fixtures/property.pyi]

Here's the traceback:

/Users/jukka/src/mypy/mypy/test/testcheck.py:105: in run_case
    self.run_case_once(testcase, step)
/Users/jukka/src/mypy/mypy/test/testcheck.py:169: in run_case_once
    alt_lib_path=test_temp_dir)
/Users/jukka/src/mypy/mypy/build.py:180: in build
    result = _build(sources, options, alt_lib_path, bin_dir, saved_cache, flush_errors)
/Users/jukka/src/mypy/mypy/build.py:266: in _build
    graph = dispatch(sources, manager)
/Users/jukka/src/mypy/mypy/build.py:2114: in dispatch
    process_graph(graph, manager)
/Users/jukka/src/mypy/mypy/build.py:2421: in process_graph
    process_stale_scc(graph, scc, manager)
/Users/jukka/src/mypy/mypy/build.py:2621: in process_stale_scc
    graph[id].write_cache()
/Users/jukka/src/mypy/mypy/build.py:2071: in write_cache
    self.manager)
/Users/jukka/src/mypy/mypy/build.py:1260: in write_cache
    data = {'tree': tree.serialize(),
/Users/jukka/src/mypy/mypy/nodes.py:247: in serialize
    'names': self.names.serialize(self._fullname),
/Users/jukka/src/mypy/mypy/nodes.py:2521: in serialize
    data[key] = value.serialize(fullname, key)
/Users/jukka/src/mypy/mypy/nodes.py:2456: in serialize
    data['node'] = self.node.serialize()
/Users/jukka/src/mypy/mypy/nodes.py:2229: in serialize
    'names': self.names.serialize(self.fullname()),
/Users/jukka/src/mypy/mypy/nodes.py:2521: in serialize
    data[key] = value.serialize(fullname, key)
/Users/jukka/src/mypy/mypy/nodes.py:2458: in serialize
    data['type_override'] = self.type_override.serialize()
/Users/jukka/src/mypy/mypy/types.py:955: in serialize
    'items': [t.serialize() for t in self.items()],
/Users/jukka/src/mypy/mypy/types.py:955: in <listcomp>
    'items': [t.serialize() for t in self.items()],
/Users/jukka/src/mypy/mypy/types.py:870: in serialize
    'ret_type': self.ret_type.serialize(),
/Users/jukka/src/mypy/mypy/types.py:1429: in serialize
    assert False, "Internal error: Unresolved forward reference to {}".format(name)
E   AssertionError: Internal error: Unresolved forward reference to C

It looks like we don't remove forward references in the type_override attribute of symbol table nodes.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions