Fix wrong exhaustive check with sequence wildcard on case class with custom unapply#24260
Conversation
7dabd1e to
445195f
Compare
|
|
||
| @main def run(): Unit = | ||
| Test() match | ||
| case Test(x*) => println(x) // warn |
There was a problem hiding this comment.
Shouldn't we disallow this sequence pattern, as there is no unapplySeq in object Test?
There was a problem hiding this comment.
Hi, thanks, yes!!
I agree this aligns with the spec, and I've updated the PR to emit an error instead of a warning, but I'm a bit concerned about potential backward compatibility for code that may have relied on this being silently accepted.
|
While testing some other examples, I'm surprised that case class Test()
object Test:
def unapplySeq(t: Test): Option[Seq[Int]] = Some(Seq(1, 2))
object TTest:
def unapplySeq(t: Test): Option[Seq[Int]] = Some(Seq(1, 2))
@main def run(): Unit =
Test() match
case Test(x*) => () // error: Wrong number of argument patterns for Test; expected: ()
Test() match
case TTest(x*) => () |
4868a7c to
484c1e5
Compare
@noti0na1 |
|
Bump @noti0na1 |
Fixes #23459
Based on Scala Lang Spec