Closed
Description
This compiles with scalac but not with dotty:
import scala.util.Random
object Test {
def test = {
val rand = new Random
rand.shuffle(List(1,2)) // fails
}
}
try/t6948b.scala:6: error: no implicit argument of type scala.collection.generic.CanBuildFrom[
(CC?
>: ([+HK$0] => scala.collection.immutable.List[HK$0])[HK$0 =+ (T? >: Int)]
<:
([HK$0] => <: scala.collection.TraversableOnce[HK$0])
)[(T? >: Int)]#Apply
, (T? >: Int),
(CC?
>: ([+HK$0] => scala.collection.immutable.List[HK$0])[HK$0 =+ (T? >: Int)]
<:
([HK$0] => <: scala.collection.TraversableOnce[HK$0])
)[(T? >: Int)]#Apply
] found for parameter bf of method shuffle in class Random
rand.shuffle(List(1,2))
^
one error found
But explicitly doing an implicit search is enough to make it work:
import scala.util.Random
import scala.collection.generic._
import scala.collection.immutable._
object Test {
implicit val z: CanBuildFrom[List[Int], Int, List[Int]] =
implicitly[CanBuildFrom[List[Int], Int, List[Int]]] // succeeds
def test = {
val rand = new Random
rand.shuffle(List(1,2)) // now succeeds
}
}
Metadata
Metadata
Assignees
Labels
No labels