Open
Description
This is a simplification of Enumeration#ValueSet
which has the same issue.
package scala
import collection.immutable
import collection.mutable
import collection.BuildFrom
abstract class MySet
extends /*immutable.AbstractSet[String]
with*/ immutable.Set[String]
with immutable.SetOps[String, immutable.Set, MySet] {
override protected def fromSpecific(coll: IterableOnce[String]): MySet = ???
override protected def newSpecificBuilder: mutable.Builder[String, MySet] = ???
override def empty: MySet = ???
}
class SetTest {
implicit class MappExt[A, CC <: Iterable[A]](c: CC with collection.IterableOps[A, collection.AnyConstr, CC]) {
def mapp[B, That](f: A => B)(implicit cbf: BuildFrom[CC, B, That]): That = {
val b = cbf.newBuilder(c)
c.foreach(b += f(_))
b.result()
}
}
// these fail with the `AbstractSet` parent
def t(s: MySet) = s.mapp(_ => 1)
implicitly[BuildFrom[MySet, String, immutable.Set[String]]]
implicitly[BuildFrom[MySet, String, immutable.Set[String]]](BuildFrom.buildFromIterableOps)
// works also with `AbstractSet`
implicitly[BuildFrom[MySet, String, immutable.Set[String]]](BuildFrom.buildFromIterableOps[immutable.Set, String, String])
// original example
En.values.mapp(_.toString)
}
object En extends Enumeration {
val X = Value("x")
}
This compiles, but when un-commenting the AbstractSet
parent it fails.
When changing MySet
to MySet[T]
and adjusting the immutable.SetOps[String, immutable.Set, MySet]
parent to immutable.SetOps[String, MySet, MySet[T]]
, things work also with the AbstractSet
parent.
Maybe this is a puzzle that can be solved, I didn't manage so far.