scalacenter/scala

Precise type is lost on dependent method

Closed this issue · 2 comments

FooBar.scala (dotty 0.22)

trait Foo {
  type T
  def foo: T
}

class Bar[Foo1 <: Foo] {
  def bar(foo: Foo1): foo.T = {
    foo.foo
  }
}

TestFooBar.scala (tasty enabled scala 2)

object TestFooBar {

  class FooString extends Foo {
    type T = String
    def foo = "I am foo"
  }

  class FooInt extends Foo {
    type T = Int
    def foo = 23
  }

  val b1 = new Bar[String, FooString]
  val b2 = new Bar[Int, FooInt]
  def test1 = assert((b1.bar(new FooString): String) === "I am foo")
  def test2 = assert((b2.bar(new FooInt): Int) === 23)

}

Error on compile scala 2

[error] TestFooBar.scala:15: error: type mismatch;
[error]  found   : Foo.this.T
[error]  required: String
[error]    def test1 = assert((b1.bar(new FooString): String) === "I am foo")
[error]                              ^
[error] TestFooBar.scala:16: error: type mismatch;
[error]  found   : Foo.this.T
[error]  required: Int
[error]   def test2 = assert((b2.bar(new FooInt): Int) === 23)
[error]                             ^
[info] 2 errors

issue appears to be in the implementation for SELECTtpt TASTy tag

fixed by #55