Skip to content

Nested exhaustive match/case not refining the type #5011

Description

@marpulli

Describe the Bug

If a nested match/case statement returns on all branches, it doesn't correctly refine the type from the outer branch.

In this example, I'd expect "z" to be inferred as non-null after the if statement but it is inferred as int | None.

from typing import reveal_type, Sequence
from typing import *


AdmitOrReject = Literal["admit", "reject"]

def x(z: int | None, y: AdmitOrReject):
    if z is None:
        match y:
            case "admit":
                return 5
            case "reject":
                return 5
    reveal_type(z)
    return z
    

x(5, "reject")

Sandbox Link

https://pyrefly.org/sandbox/?project=v2.pZW_DoIwEMZfpcEBYoidWEgcfAKNq10aaIABMFAN9un9rtBYlGCMbPT-tNf73dcfJNPTGV8iFjy31CXRHPK60sfurCy_eyebFxFIsoggRkGdtYrADiiBM0QmRWcd8DF7pGyWyTEKZMwC7bXUWYmg1wp9EE2F3aaN34we7climDvk1zjvjiIDCj0PM_5RmUOU-KVPfmT5hGrDTuMCm_oDOQWNxQ2iDcp2otmgGYqVWl_7lHMX3nYFVw3P26znswjOaH7kXVb2KZinY60dgh5p_6E5HGEO11gOCWV4rOL5BA

(Only applicable for extension issues) IDE Information

No response

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions