Inconsistent handling of match types in pattern matching #17720
Replies: 3 comments
-
Minimization: trait Unapplyable[A] {
def unapply(s: String): Option[A]
}
val unapp1: Unapplyable[(String, String)] = ???
val unapp2: Unapplyable[String *: String *: EmptyTuple] = ???
def test = "a;b" match
case unapp1(a, b) => () // OK
case unapp2(a, b) => () // error |
Beta Was this translation helpful? Give feedback.
-
This is actually as specced. The pattern What happens for To change any of this we'd need to define some machinery that turns |
Beta Was this translation helpful? Give feedback.
-
We've already started to add more support of being able to select the components of a generic tuple. So I'll have a look at this. |
Beta Was this translation helpful? Give feedback.
-
Hey all,
while playing around with extractors and compile time ops, I noticed something which might be a compiler bug. When one has an
unapply: Option[(String, String)]
, one normally only needs one layer of parentheses in a pattern match, i.e.case Unapply(a, b) => ...
. But when I derived the(String, String)
type via match types and used two different approaches which to me seemed equivalent, one of them required an extra level of parentheses, i.e.case Unapply((a, b)) => ...
.If I had to guess, one of those two methods is not reduced to a tuple at the time the patmat code checks whether it is a tuple, but of course I have no knowledge of the compiler internals. The code is below, you can find a scastie here: https://scastie.scala-lang.org/HfRYp0utTNKjRQjptpVrFQ
Compiler version
3.1.2
Minimized code
Output
Expectation
It should compile. Both should use the same number of parentheses.
Beta Was this translation helpful? Give feedback.
All reactions