-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GADT pattern matching fails to infer type equations #12478
Comments
Here is a weird workaround: def some1[T](foo: Foo[T]): Foo[Option[T]] =
foo match {
case foo: (foo.type & Foo.Bar[f]) =>
Foo.Bar[[x] =>> Option[f[x]]](foo.fu.map(Option(_)))
} It does give off a spurious exhaustivity warning, probably for the same reason as in #12475 (comment) |
@LPTK Thanks for the workaround. |
|
@dwijnand what version is "now", and what's the compiling code? |
enum Foo[T] {
case Bar[F[_]](fu: List[F[Unit]]) extends Foo[F[Unit]]
}
// the same thing, but with type annotations and comments
def some2[T](foo: Foo[T]): Foo[Option[T]] =
foo match {
// capturing the type parameter of Bar into a type variale `f`
case bar : Foo.Bar[f] =>
// now it is known that T = f[Unit]
val fu = bar.fu
val fu1: List[Option[f[Unit]]] =
fu.map(Option(_))
val res: Foo[Option[f[Unit]]] =
Foo.Bar[[x] =>> Option[f[x]]](fu1)
// given that f[Unit] = T,
// `res` should pass as a return value of type Foo[Option[T]]
res
} I just tested with 3.2.2. |
I just checked and your version compiles already in 3.0.0, so that doesn't show any improvement compared to when this issue was raised, just another workaround. |
Then is the bug you're having that this minimisation doesn't compile? enum Foo[T] {
case Bar[F[_]](fu: List[F[Unit]]) extends Foo[F[Unit]]
}
def wrap[F[_]](fu2: List[Option[F[Unit]]]): Foo[Option[F[Unit]]] =
Foo.Bar(fu2) |
Not really, but thanks for helping me realize that the original example would require to infer The bug that's bugging me can be simplified to this not compiling: enum Foo[T] {
case Bar[F[_]](fu: List[F[Unit]]) extends Foo[F[Unit]]
}
def identity[T](foo: Foo[T]): Foo[T] =
foo match {
case Foo.Bar(fu) =>
Foo.Bar(fu)
} |
It is a regression from 2.x. The following compiles in 2.13.10, but not in 3.2.2: sealed trait Foo[T]
object Foo {
case class Bar[F[_]](fu: List[F[Unit]]) extends Foo[F[Unit]]
}
def identity[T](foo: Foo[T]): Foo[T] =
foo match {
case Foo.Bar(fu) =>
Foo.Bar(fu)
} |
Compiler version
3.0.0
Minimized code
Output
Expectation
The code should compile, the comments in the
some2
method explain why.The text was updated successfully, but these errors were encountered: