Scala 3 puzzle about opaque type

It compiles with covariant C.

trait C[+D]

enables

override def foo: G & E & I = new G with E with I

for reasons that escape me. I was curious what if B were wider than the arg in G.

opaque type B = P
class G extends C[Q]
trait P
trait Q extends P

Edit: meant to say something about “bridge” pattern. Although this example looks like extension, the encapsulation says composition, and I expected to arrive at something that uses export to easily create a delegate. That is, super.mkGE knows how to build G & E, and subclass delegates to it and implements I members.

1 Like