Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit search fails for new Random.shuffle(List(1,2)) #553

Closed
smarter opened this issue May 9, 2015 · 1 comment
Closed

Implicit search fails for new Random.shuffle(List(1,2)) #553

smarter opened this issue May 9, 2015 · 1 comment

Comments

@smarter
Copy link
Member

smarter commented May 9, 2015

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
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant