Skip to content

Pyrefly should narrow subsequent match cases after None case #3213

@rchen152

Description

@rchen152

Describe the Bug

Pyrefly emits false positives on this code:

def example(a: list[int] | None, b: list[int] | None) -> list[int]:
  match (a, b):
      case (None, None):
          return []
      case (_, None):
          return a       # error: int | None not assignable to list[int]
      case (None, _):
          return b       # error: int | None not assignable to list[int]
      case _:
          return a + b    # error: int | None not assignable to list[int]

(sandbox). Pyright accepts it.

Sandbox Link

No response

(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