Open
Description
Compiler version
3.7.1-RC1-bin-20250328-d519790-NIGHTLY
Minimized example
class CustomProduct(x: Int) extends Product {
def _1 = someName
def _2 = blub
val someName = x + 5
val blub = "blub"
override def canEqual(that: Any): Boolean = ???
}
object ProductMatch {
def unapply(x: Int): CustomProduct = new CustomProduct(x)
}
@main
def run = {
3 match {
case ProductMatch(someName = x) => println (x)
}
}
Output Error/Warning message
No element named `someName` is defined in selector type CustomProduct
case ProductMatch(someName = x) => println (x)
Why this Error/Warning was not helpful
The message was unhelpful because there is actually an element called someName
on CustomProduct
.
Suggested improvement
I think the message should be something more like
CustomProduct is not a valid selector type for the use with named patterns.
Only named tuples and case classes can be used with named patterns.