It seems that you should write,
trait X[T <: X[T]] object Y extends X[Y.type]
however, if you try to have the compiler provide you with a useless (and I think false) error,
scala> object Y extends X[Y.type] <console>:16: error: illegal cyclic reference involving object Y object Y extends X[Y.type]
I say βfalseβ because we can build an equivalent facility with a little extra infrastructure,
trait X[T <: X[T]] trait Fix { type Ytype >: Y.type <: Y.type; object Y extends X[Ytype] } object Fix extends Fix { type Ytype = Y.type } import Fix.Y
If you want to experiment with this in real code, using a package object Fix instead of object Fix will make this idiom more convenient.
source share