You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’ve discovered this issue when working on the collections strawman.
importscala.reflect.ClassTag// Base type introducing a flatMap methodtraitColl[A] {
defflatMap[B](f: A=>Coll[B]):Coll[B]
}
// An `Arr[A]` is not a `Coll[A]` ...traitArr[A]
// ... but there is an `ArrOps` decoratortraitArrOps[A] extendsColl[A] {
// we overload `flatMap` for the specific needs of `Arr`defflatMap[B:ClassTag](f: A=>Coll[B]):Arr[B]
}
objectPrelude {
importscala.language.implicitConversionsimplicitdefarrToArrOps[A](array: Arr[A]):ArrOps[A] =???
}
objectUsageextendsApp {
importPrelude._valarray:Arr[Arr[Int]] =???// This line doesn’t compile
array.flatMap(x => x)
// overloaded method value flatMap with alternatives:// [B](f: Arr[Int] => Coll[B])(implicit evidence$1: scala.reflect.ClassTag[B])Arr[B] // [B](f: Arr[Int] => Coll[B])Coll[B]// cannot be applied to (Arr[Int] => Arr[Int])// However if we explicitly trigger the implicit conversion to `Coll`, it compiles:
array.flatMap(x => (x: Coll[Int]))
// Also, if we remove the overload the first one compiles too (even though it requires// two implicit conversions: one to make the `flatMap` method available and one to make// the the result of the function passed to `flatMap` a `Coll`
}
Tested with Dotty 0.4.0-RC1. Scalac behaves exactly in the same way (see scala/bug#10576)
The text was updated successfully, but these errors were encountered:
I’ve discovered this issue when working on the collections strawman.
Tested with Dotty 0.4.0-RC1. Scalac behaves exactly in the same way (see scala/bug#10576)
The text was updated successfully, but these errors were encountered: