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
Name-based pattern match CCE on Tuple1 #7897
Comments
Imported From: https://issues.scala-lang.org/browse/SI-7897?orig=1 |
@paulp said: |
@som-snytt said: I have a spec question. Boolean match is achieved by unapply returning boolean. What about The additional use case is that in a macro, it's more symmetrical or regular to generate the return of get in one place. I already worked around #7897 in the obvious way, class Nada(s: String) extends AnyRef {
def isEmpty = s != "null"
def get: Boolean = !isEmpty
override def toString = "Nada"
}
object Nada {
def unapply(x: Any): Nada = new Nada(String.valueOf(x))
} Trying to eliminate the bad: null match {
case p0.Nada(/*bad*/) => println(s"matched Nada")
case _ => println("no matchada")
} |
@paulp said: |
@paulp said: Also, it's important that get returning boolean is not the same use case. If get returns boolean the unapply encodes three possible outcomes. If the unapply returns boolean it encodes two possible outcomes. If I were designing my own pattern matcher there would be a first class Product and all extractors would return some efficiently encoded variation of Option[Product[Arity]], but as it is there's not going to be a way to abstract uniformly over unapply return types. |
@paulp said: |
The name-based pattern matcher doesn't like a Product1 extractor.
The extracted value is taken as
v
instead ofv._1
.Here is the test added to
test/files/run/name-based-patmat.scala
:This throws CCE:
FWIW, I was working from this spec (i.e. commit comment):
"If it does not contain _1, then it is a single value
extractor analogous like Option[T]."
The text was updated successfully, but these errors were encountered: