The following code does not compile with Scala 2.12.4. However, it compiles unchanged with Dotty 0.4.0-RC1. If all variance annotations in the BFlow1 trait are dropped then it also compiles with Scala 2.12.4.
Expected (wished?) behaviour: The code should also compile with Scala 2.12.4.
Interestingly, it also compiles when only the variance annotation of the type parameter O2 is dropped. Scalac does not detect the resulting variance mismatch, that IntelliJ reports for the that argument: "Contravariant type I2 occurs in invariant position in type Test1.BFlow1")
object Test1 {
trait BFlow1[-I1, +O1, -I2, +O2] {
def atop[OO1, II2](
that: BFlow1[O1, OO1, II2, I2]
): BFlow1[I1, OO1, II2, O2] = ???
}
// a factory for a bidiflow that does not change the input and output while it passes through
def layer[In, Out](): BFlow1[In, In, Out, Out] = ???
val bf: BFlow1[Int, Int, String, String] = ???
val res: BFlow1[Int, Int, String, String] = bf
// Error: type mismatch;
// found : Test1.BFlow1[Int,Int,Nothing,Nothing]
// required: Test1.BFlow1[Int,Int,II2,String]
// .atop(layer())
.atop(layer())
.atop(layer())
}
The following code does not compile with Scala 2.12.4. However, it compiles unchanged with Dotty 0.4.0-RC1. If all variance annotations in the BFlow1 trait are dropped then it also compiles with Scala 2.12.4.
Expected (wished?) behaviour: The code should also compile with Scala 2.12.4.
Interestingly, it also compiles when only the variance annotation of the type parameter
O2
is dropped. Scalac does not detect the resulting variance mismatch, that IntelliJ reports for thethat
argument: "Contravariant type I2 occurs in invariant position in type Test1.BFlow1")The code shows a problem with implementing a BidiFlow similarly to https://doc.akka.io/api/akka/current/akka/stream/scaladsl/BidiFlow.html