Skip to content

Union rules trigger duplicates on nested violations #6285

Closed
@charliermarsh

Description

@charliermarsh

In expression.rs, we have some logic to avoid checking nested Union operators, since our Union checks operate recursively (and so re-checking nested Union operators leads to duplicate diagnostics).

These checks don't quite work in .pyi files due to the way we process deferred nodes. We don't store the current expression stack when snapshotting the SemanticModel, because that would require us to store all expressions in an IndexVec. This is a known source of bugs.

We can store the expressions in an IndexVec, like we do for statements, but it will definitely hurt performance and increase memory usage.

As an example, if this is put in a .pyi file:

from typing import Union

Union[int, Union[int, int]]

You'll hit duplicate violations:

foo.pyi:3:22: PYI016 Duplicate union member `int`
foo.pyi:3:27: PYI016 Duplicate union member `int`
foo.pyi:3:27: PYI016 Duplicate union member `int`

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions