Skip to content

Sequence pattern in match/case does not narrow tuple out of a union #3147

@adamtheturtle

Description

@adamtheturtle

Describe the Bug

from typing import assert_never


def f(value: float | tuple[float, float]) -> None:
    match value:
        case (_, _):
            pass
        case float():
            pass
        case _ as unreachable:
            assert_never(unreachable)

unreachable should be narrowed to Never after the sequence and class patterns have matched all arms of the union.

ERROR Argument `tuple[float, float]` is not assignable to parameter `arg` with type `Never` in function `typing.assert_never` [bad-argument-type]
  --> repro.py:11:26
   |
11 |             assert_never(unreachable)
   |                          ^^^^^^^^^^^

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN2o4cGHwD66GADcRAHXRy5mGGDpgAFJNRQArjESqouVPwA%2BjbcVgBtMIeMAaA0YYBdAJR0AtAD46AOVwJRDk6ULoaYwBjAAs6TR09ELDkyMEYOjVRR1E3YPRkgrDiQTgkwtThJ2M1XLLCopK6lLS6UQE4Om10ShhUGNRsWDz6gpKRBnEpETUunr7ogdg3ORB7EDIe21JCBlooCgBiOgAFUk2oUjo0LDx8OkjAyDZtSmMIQMI5I4BlGHTohgMYhwRAAelBG2UF0IvDYoJg6FBmFwkTgoIe6CeLzegVBql4Ak00EW6QxWNeDHe%2BVwxEpgTgn3QZAY0UCnmklDgVLoAF46DIQABmQgARgATAK5FYRNROS45F0uDw%2BDBMJ5MBAepFKdJeXQAOQQNjoXgwfVyE0MTw9ACO2k1qs8AGsYKRPH1IvAOnz9QB3VCUdDm9AgAC%2Baz6OpgADFoDAKNccAQSORQ0A

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    narrowingIssues with narrowing - root cause is usually narrowing, flow handling, or bothtypechecking

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions