pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

`unbound-name` does not consider exhaustiveness of `match ... case` correctly

Open DanielNoord opened this issue 1 month ago • 2 comments

Describe the Bug

from typing import assert_never, Literal

def func(x: Literal[1, 2]) -> None:
    match x:
        case 1:
            y = 1
        case 2:
            y = 1
        case _:
            assert_never(x)

    print(y)
ERROR sandbox.py:12:11-12: `y` may be uninitialized [[unbound-name](https://pyrefly.org/en/docs/error-kinds/#unbound-name)]

Python: 3.12

y is not undefined here :)

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxlKnHAAQCCiAOuvR-ZjGPWAK7pKACjgwoYADT18iehHQAXAJT0AtAD56AOVzoYcwkbbVaDAELDGy1u07deAoaPFT6AfTkKV6rbv2GxuggkiD8itBwJOSIIADE9ACqEVAQiqR8gpQRenBsbA58uABOALaoiu7o-KXYMMXCsvJKqpr0cIrFtpz0xTCK-MXsYCwg2jV1XfTA%2BAC%2Bo2whIGR9YFCkhIq4pVAUCQAKpKvr7Rg4BPSUepAA5oMVEHqEbAkAyjAw9AAWiorEcIgAPSAlY8daEEo3QEwdCAzC4ShwQFXdC3e45WFFYr0VAAN1Q0FQ2Fgl2uEDuxQeenouGIGKibDIii%2BejUuPqcEe7AAvPRRgBmQgARgATAtgrNQqhshB2QAxaAwChoLB4IhkECzIA

(Only applicable for extension issues) IDE Information

No response

DanielNoord avatar Nov 28 '25 12:11 DanielNoord

Thanks for the bug report!

We're currently missing exhaustiveness on match entirely, it's tracked in https://github.com/facebook/pyrefly/issues/1286

This should be done before the V1 release

stroxler avatar Nov 28 '25 15:11 stroxler

This is similar to https://github.com/facebook/pyrefly/issues/1518, but for literals instead of enums.

rchen152 avatar Dec 01 '25 20:12 rchen152