F-Bounded type - why is the infered type Any?


Can anyone tell me why this fails to compile:

  trait GTT[T, S <: GTT[T,_] ] { this : S =>
    def add(e: ATT[T]): S
    def reverse: S

    def toGColumns: Either[List[Throwable], S] = {
      val tmp: (S, Int) = Tuple2[S,Int](this,1)
      val rr: S = tmp._1
      val r2 : S = rr.reverse

Compiler states that:

found   : _$1
[error]  required: S
[error]       val r2 : S = rr.reverse

However, If I return


I have no problem.

rr has type S which is a subtype of GTT[T,_]. So the compiler doesn’t know which type rr.reverse returns (its type is _ …). He doesn’t know whether or not that type conforms to S.

Hi Jasper-M

Ok. I understand now. That is an error on my part. I should have declared:

trait GTT[T, S <: GTT[T,S] ] { this : S =>

I also understand why


works. Compiler could not figure out what the “_” was but it knows it did not change (tuple returns the same type) - hence stays equal to the expected S.

You’re a life saver. Thanks. Appreciate it.