tribbloid
tribbloid

Reputation: 3858

How to abstract over higher-kind with F-bounded polymorphism in Scala3? The same definition works in Scala2

Assuming that several objects in Scala share an identical definition of nested generic class or trait H, with only 1 Peer type defined using F-bounded polymorphism:

object Example {

  trait P {

    type H[Peer <: H[Peer]]
  }

  object P1 extends P {
    trait H[Peer <: H[Peer]]
  }
  object P2 extends P {
    trait H[Peer <: H[Peer]]
  }

//  object KO extends P1.HH
}

This compiles with absolutely no problem in Scala 2.13.10. But on Scala 3.2.1 it causes the following error:

....scala:25:20: Cyclic reference involving type H
one error found

What may have caused this definition to violate the underlying type calculus? Can the type system still regard as GADT-friendly if such definition can't be supported?

Upvotes: 1

Views: 99

Answers (0)

Related Questions