Skip to content

Simple enhancement for pattern matching with capturing types #23524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

noti0na1
Copy link
Member

The bind variable should carry the capture set from the selector during pattern matching.

import language.experimental.captureChecking

trait A

case class B(x: AnyRef^) extends A

def test =
  val x: AnyRef^ = new AnyRef
  val a: A^{x} = B(x)

  val y1: A = a match
    case b: B => b // error: (b: B) becomes B^{x} implicitly

  val y2: A^{x} = a match
    case b: B => b // ok

  val x3: AnyRef = a match
    case B(x2: AnyRef) => x2 // error: we lose some information about field x, but it still cannot be pure

  val x4: AnyRef = a match
    case b: B => b.x // error

@noti0na1 noti0na1 requested a review from Copilot July 14, 2025 14:31
Copilot

This comment was marked as resolved.

@noti0na1 noti0na1 marked this pull request as ready for review July 14, 2025 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant