The typer phase (scala -Xprint:typer
) hides the answer:
private[this] val res7: <error> = Predef.intWrapper(1).to(6).toSet[B].map[B, That]({
((x: Nothing) => Predef.identity[Nothing](x))
})();
(1 to 6)
returns a Range.Inclusive, which is a first-order type and not a type constructor, it's not parameterized, but Set[A]
expects/requires you to provide it some type and returns you a type. When you call toSet
, scalac expects some type, cause Inclusive
doesn't have toSet
method, it's inherited from TraversableOnce
and is a generic method, so you need explicitly provide some type:
(1 to 6).toSet[Int].map(identity)
res0: scala.collection.immutable.Set[Int] = Set(5, 1, 6, 2, 3, 4)
toBuffer
also doesn't work, other conversions works perfectly and this two methods have a similar implementation:
def toBuffer[B >: A]: mutable.Buffer[B] = to[ArrayBuffer].asInstanceOf[mutable.Buffer[B]]
def toSet[B >: A]: immutable.Set[B] = to[immutable.Set].asInstanceOf[immutable.Set[B]]