Skip to content

Report unreachable duplicate partial-class match cases #5516

Open

Description

@bniladridas

Describe the Bug

Pyrefly reports unreachable match cases for full class patterns, but not for duplicate or subsumed partial class patterns.

from typing import Any

class A:
    x: int

class B(A):
    pass

def f(x: Any) -> None:
    match x:
        case A(x=1):
            pass
        case A(x=1):  # should be unreachable
            pass

The duplicate is also not reported for a precise A subject, so this is a pre-existing reachability limitation rather than one specific to Any.

Expected behavior

The second A(x=1) case should be reported as unreachable because the first unguarded case already matches the same values.

case A(x=1) followed by case B() must remain reachable because a subclass instance may have a different x.

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions