Closed
Description
Type inferred inside for-comprehension is a union Any | X
where X
is expected
Compiler version
3.1.2
Works with 3.1.1
Fails in 3.1.3-RC3
Fails in 3.2.0-RC1-bin-20220517-e5abec0-NIGHTLY
Minimized code
//> using scala "3.1.2"
// //> using scala "3.1.1" // Last working stable version
sealed abstract class Free[S[_], A] {
final def map[B](f: A => B): Free[S, B] = ???
final def flatMap[B](f: A => Free[S, B]): Free[S, B] = new Free[S, B] {}
}
trait Parameter[T]
def namedDouble(name: String): Free[Parameter, Double] = ???
type Double2 = (Double, Double)
type Double3 = (Double, Double, Double)
val spec: Free[Parameter, Either[Double3, Double2]] = for {
result <-
if (???) {
for {
x <- namedDouble("X")
y <- namedDouble("Y")
z <- namedDouble("Z")
} yield Left((x, y, z))
} else {
for {
x <- namedDouble("X")
y <- namedDouble("Y")
} yield Right((x, y))
}
} yield result
Output
[error] ./test.scala:28:9: Found: (result : Either[Any | (Double, Double, Double), (Double, Double) | Any])
[error] Required: Either[Double3, Double2]
[error] } yield result
[error] ^^^^^^