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
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.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