-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Labels
Description
In this following code the overridden declaration of fact
in Iterable
makes type inference fail for g
and h
The version in f
where the additional type information is deliberately dropped, compiles successfully.
object IterableTest {
trait IterableOps[+CC[_]] {
def fact: IterableFactory[CC]
}
trait Iterable[+A] extends IterableOps[Iterable] {
override def fact: IterableFactory[Iterable]
}
trait IterableFactory[+CC[_]]
def f[CC[_] <: Iterable[_] with IterableOps[CC]](from: CC[_]): IterableFactory[CC] = (from: IterableOps[CC]).fact
def g[CC[_] <: Iterable[_] with IterableOps[CC]](from: CC[_]): IterableFactory[CC] = (from: Iterable[_] with IterableOps[CC]).fact
def h[CC[_] <: Iterable[_] with IterableOps[CC]](from: CC[_]): IterableFactory[CC] = (from ).fact
}
This fails to compile (tested with Scala 2.12.2, 2.12.4 and 2.13.0-M3) with:
IterableTest.scala:13: error: type mismatch;
found : IterableTest.IterableFactory[IterableTest.Iterable]
required: IterableTest.IterableFactory[CC]
def g[CC[_] <: Iterable[_] with IterableOps[CC]](from: CC[_]): IterableFactory[CC] = (from: Iterable[_] with IterableOps[CC]).fact
^
IterableTest.scala:14: error: type mismatch;
found : IterableTest.IterableFactory[IterableTest.Iterable]
required: IterableTest.IterableFactory[CC]
def h[CC[_] <: Iterable[_] with IterableOps[CC]](from: CC[_]): IterableFactory[CC] = (from ).fact
It works in Dotty (current master branch).