-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Labels
fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)inferlibrary:collectionsminimizedtyperusability
Milestone
Description
In the following code, bar1 and bar2 are equivalent:
trait Foo[A] {
def up[A1 >: A]: Foo[A1]
def bar1(x: Foo[_ >: A]): Foo[A]
def bar2[A1 >: A](x: Foo[A1]): Foo[A]
}
object Test {
def test(a: Foo[Int], b: Foo[Any]) = {
val x1 = a.up.bar1(b)
val x2 = a.up.bar2(b)
}
}However, type inference works better for bar2 (in Dotty, both are inferred to Foo[Int]):
val x1: Foo[Any] = a.up[Any].bar1(b);
val x2: Foo[Int] = a.up[Int].bar2[Any](b);It'd be good to figure out whether or not this can be fixed since this affects the API of the collections, in 2.13 we currently have in Seq:
def diff(that: Seq[_ >: A]): CWhich means that in the following code, x is inferred to have type Buffer[Any] and not Buffer[Int]:
object Test {
def test(a: Seq[Int], b: Seq[Any]): Unit = {
val x = a.toBuffer.diff(b)
}
}Metadata
Metadata
Assignees
Labels
fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)inferlibrary:collectionsminimizedtyperusability