Closed
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.
Activity
SrTobi commentedon Apr 1, 2025
I found this while implementing the logic in IntelliJ. Pls ping me if some underlying concept changes (like allowing named patterns on custom selector types)
mbovel commentedon Jun 9, 2025
This issue was picked for today's Scala Issue Spree. @jan-pieter, @nmcb, @RoccoMathijn, Thijs and Wessel will be working on it! If you have any insight into the issue or guidance on how to fix it, please leave it here.
jan-pieter commentedon Jun 9, 2025
@thijsnissen @wwbakker ^