Closed
Description
In the following code:
class Foo[A](x: A) { override def toString = "Foo(" + x + ")" }
class Bar[A](x: A) extends Foo[A](x) { override def toString = "Bar(" + x + ")" }
object Foo {
implicit val f: Foo[Int] = new Foo(42)
}
object Bar {
implicit val b: Bar[Int] = new Bar(42)
}
object Test {
def printImplicit[CC[X] <: Foo[X]](x: CC[Int])(implicit ev: CC[Int]) = println(ev)
def main(args: Array[String]) = {
printImplicit(new Foo(1)) // print "Foo(42)"
printImplicit[Bar](new Bar(1)) // print "Bar(42)"
printImplicit(new Bar(1)) // dotty: print "Foo(42)" || scalac: print "Bar(42)"
}
}
The third implicit in main
is not correctly inferred, because the type parameter is not precise enough:
result of try/hk.scala after frontend:
...
def main(args: Array[String]): Unit = {
Test.printImplicit[([HK$0] => <: Foo[HK$0])](new Foo[Int](1))(Foo.f)
Test.printImplicit[Bar](new Bar[Int](1))(Bar.b)
Test.printImplicit[([HK$0] => <: Foo[HK$0])](new Bar[Int](1))(Foo.f)
}
scalac
handles this correctly:
[syntax trees at end of typer]] // hk.scala
...
def main(args: Array[String]): Unit = {
Test.this.printImplicit[Foo](new Foo[Int](1))(Foo.f);
Test.this.printImplicit[Bar](new Bar[Int](1))(Bar.b);
Test.this.printImplicit[Bar](new Bar[Int](1))(Bar.b)
}
Fixing this is necessary to replace #716 by a proper fix, see the work-in-progress at https://github.com/smarter/dotty/commits/fix/missing-implicits .
@odersky : Note that this also happens after applying #731 .
Metadata
Metadata
Assignees
Labels
No labels