I'm learning Scala, and am stuck with an error involving generics. I've defined a trait as
trait myTrait[
A, B,
Self[X, Y] <: myTrait[X, Y, Self]] {
protected def self: Self[A, B]
}
and my class as
class myClass[B] extends myTrait[Int, B, myClass]{
override protected def self:myClass[B] = this
}
This gives me a compile error "illegal cyclic reference involving class myClass". The error goes away if I declare myClass as
class myClass[A, B] extends myTrait[A, B, myClass]{
override protected def self:myClass[A, B] = this
}
What am I doing wrong?
That's not the error I get in 2.11.7:
myClass takes one type parameter, expected: two
Which makes sense: myClass is used as the Self argument of MyTrait, which requires two type parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With