Why scala does not unify this type lambda with underlying type?

前端 未结 3 1493
trait A {
  type T
  def test(t: T): Unit
}

case class B[S <: A](a: S, t : S#T) {
  def test() = a.test(t) // Error: type mismatch;
    // found   : B.this.t.typ         


        
3条回答
  •  北恋
    北恋 (楼主)
    2021-01-12 15:17

    Instead of a type projection you can use the dependent type a.T:

    trait A {
      type T
      def test(t: T): Unit
    }
    
    case class B[S <: A](a: S)(t : a.T) {
      def test() = a.test(t)
    }
    

提交回复
热议问题