Reproduction steps
Scala version: 2.13.16
trait Contains[-C, -X] {
def apply(items :C, item :X) :Boolean
}
object SetLike {
def unapply[X](items :IterableOnce[X]) :Option[Contains[items.type, X]] =
items match {
case set :collection.Set[X @unchecked] => Some(
(new Contains[collection.Set[X], X] {
override def apply(items :collection.Set[X], item :X) :Boolean = items(item)
}).asInstanceOf[Contains[items.type, X]]
)
case _ => None
}
}
def contains[X](items :IterableOnce[X], item :X) :Boolean = items match {
case SetLike(contains) => contains(items, item)
case _ => SetLike.unapply(items) match {
case Some(contains) => contains(items, item)
case _ => items.iterator.contains(item)
}
}
Problem
type mismatch;
found : items.type (with underlying type IterableOnce[X])
required: <unapply-selector>.type
case SetLike(contains) => contains(items, item)
Calling unapply directly and then matching a value already parameterized with a singleton type, as in the second case in contains works as intended.
Reproduction steps
Scala version: 2.13.16
Problem
Calling unapply directly and then matching a value already parameterized with a singleton type, as in the second case in
containsworks as intended.