Skip to content

Pyrefly reports duplicate [bad-specialization] errors #2176

@rchen152

Description

@rchen152

Describe the Bug

See:

from typing import TypeGuard, reveal_type

def f[T: str](x: T) -> TypeGuard[T]:
    return True

def g(x: int | str):
    if f(x):
        reveal_type(x)

We correctly report a bad-specialization error on f(x), but we do it twice:

ERROR sandbox.py:7:5-8:23: `int | str` is not assignable to upper bound `str` of type variable `T` [bad-specialization]
ERROR sandbox.py:7:9-12: `int | str` is not assignable to upper bound `str` of type variable `T` [bad-specialization]

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN0AVZjADiAV1SVMAGjqUYANxiooAfSbEYAHXQ7MMMHTABtAYjpwGlALoAKfOYEBKOgFoAfIOHjJmU9cQdOmC5GAYxSnRBSjFtXSwDOjZ7c1Z%2BAB8LKydAqJCIQzB7HKCQsvklFXVhYpBpEDEGaDgSckQQAGI6AFUmqAgmIzF0AGMm3HQ4HT1EsF4aVAZVdDEabBhKFM50BhcPLMpc8rCIqLAtEAA5VfXDumB8AF8LnTqQMnkwKFJCBlooChdAAKpE%2B3wsGBwBDoIwmkDYEUWEAmhB0XQAyjAYHQABYMBjEOCIAD0xI%2BBm%2BhF4bGJMHQxMwuBGcGJsPQ8MR43pRl4dFQClQ0FQ2FgMLhEARlCREzouGIXJaOjIDBxE1cSkocGRUQAvHQLgBmQgARgATC90CBHvVUGMIEoAGLQGAUNBYPBEMhWoA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions