Closed liufengyun closed 6 years ago
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...
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: