Skip to content

conflicting-declarations error can contain duplicate types #699

Closed
astral-sh/ruff
#18750
@lipefree

Description

@lipefree

Summary

For the following snippet :

def _(flag1: bool, flag2: bool):
    if flag1:
        x: str
    elif flag2:
        x: int
    else:
        x: int

    x = 1

We will have the following error : error[conflicting-declarations]: Conflicting declared types for `x`: str, int, int. However, the list of conflicting declared types should consist of unique elements.

playground reproduction

I think it caused by the implementation logic, more specifically when adding types to the list of conflicting declared types, the code only checks if the new type is different from the first one but it should do it for all elements already in the list.

If it is caused by that, I think I can handle this issue!

Version

ty 0.0.1-alpha.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    diagnosticsRelated to reporting of diagnostics.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions