-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Spec: Are blocks allowed in patterns? #1774
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
Comments
Support could be useful for this kind of stuff: (3, 4) match {
case { val single = MyTupleExtractor(Snd); single(4) } => …
} (It makes it possible to manipulate extractors in rhs position, for instance to configure them) |
But I’m not sure it is worth it… :) |
The implementation of Quasiquote in scala.meta (link) relies on anonymous extractors like follows: new {
def unapply(input: Joy) = {
..$preamble
input match {
case $lifted => $thenp
case _ => $elsep
}
}
}.unapply(..$args) which gets expanded to a block: {
class $anon {
def unapply(input: Joy) = {
..$preamble
input match {
case $lifted => $thenp
case _ => $elsep
}
}
}
new $anon
}.unapply(..$args) |
I think it would be good to allow this! Needs a spec change, though. |
As a side note, we don't need this feature in order to implement Quasiquote in dotty. The quasi quote in Dotty now pass all regression set in scalameta. |
Close this for now, I don't think it's a good idea to have blocks in patterns, the code is not readable. |
It seems like it would open up a lot of new and interesting possibilities, though I'm a little scared about what should and shouldn't be allowed... |
Uh oh!
There was an error while loading. Please reload this page.
Scalac doesn't parse following programs syntactically, but support it if it's synthesized.
Dotty accepts the code syntactically, but the typer generates a typing error.
Error message:
The text was updated successfully, but these errors were encountered: