-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Minimal support for dependent case classes #21698
base: main
Are you sure you want to change the base?
Conversation
I am doing some experiment with dependent pattern match in CC, and this PR is useful for me as well! I modified the desuger so |
83c5e98
to
8d1c7fb
Compare
@noti0na1 Awesome! Let me know how it goes. |
b3b5331
to
3f3ce18
Compare
This used to fail with: trait <refinement> in value x extends enum EC, but extending enums is prohibited.
This lets us write: trait A: type B case class CC(a: A, b: a.B) Pattern matching works but isn't dependent yet: x match case CC(a, b) => val a1: A = a // Dependent pattern matching is not currently supported // val b1: a1.B = b val b1 = b // Type is CC#a.B (for my usecase this isn't a problem, I'm working on a type constraint API which lets me write things like `case class CC(a: Int, b: Int GreaterThan[a.type])`) Because case class pattern matching relies on the product selectors `_N`, making it dependent is a bit tricky, currently we generate: case class CC(a: A, b: a.B): def _1: A = a def _2: a.B = b So the type of `_2` is not obviously related to the type of `_1`, we probably need to change what we generate into: case class CC(a: A, b: a.B): @uncheckedStable def _1: a.type = a def _2: _1.B = b But this can be done in a separate PR. Fixes scala#8073.
I think it's probably better to wait after the cutoff with this? |
So 3.6.1 rather than 3.6.0? |
Yes, 3.6.1 should work OK. |
This lets us write:
Pattern matching works but isn't dependent yet:
(for my usecase this isn't a problem, I'm working on a type constraint API which lets me write things like
case class CC(a: Int, b: Int GreaterThan[a.type])
)Because case class pattern matching relies on the product selectors
_N
, making it dependent is a bit tricky, currently we generate:So the type of
_2
is not obviously related to the type of_1
, we probably need to change what we generate into:But this can be done in a separate PR.
Fixes #8073.