-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Union and intersection types are not causing checking the kind of type parameters #16696
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
Comments
Self-contained example: class Box[R]
class BoxMaker[T] {
def make[R <: T](f: T => Box[R]): Box[R & T] = ???
}
trait Foo[A]{
def foo: Box[Foo[Unit]]
}
val boom = BoxMaker[Foo/*[Unit]*/].make(_.foo) Uncommenting |
It still crashes on the current nightly and has been crashing since 3.0.0. |
I've played a bit with it and was able to minimise it to just: class BoxMaker[T] {
def make: T & Int = ???
}
val boom = BoxMaker[Some].make If we use union type instead of intersection, it also crashes similarly. class BoxMaker[T] {
def make: T | Int = ???
}
val boom = BoxMaker[Some].make It seems that intersections and unions are not enforcing kinds of type parameters. |
Throw a type error instead of crashing when using higher-kinded types in unions or intersections. We check kindedness only in PostTyper (to avoid cycles), which means we might get into situations where we coming a higher-kinded type in a union or intersection, which is illegal. In this case we now diagnose the problem with a TypeError instead of failing an assert. However, after Typer we do fail since by then such situations should have been checked by then. Fixeds scala#16696
…6712) Throw a type error instead of crashing when using higher-kinded types in unions or intersections. We check kindedness only in PostTyper (to avoid cycles), which means we might get into situations where we combine a higher-kinded type in a union or intersection, which is illegal. In this case we now diagnose the problem with a TypeError instead of failing an assert. However, after Typer we do fail since by then such situations should have been checked by then. Fixes #16696
Wow, thanks for getting all of these sorted for me! |
Throw a type error instead of crashing when using higher-kinded types in unions or intersections. We check kindedness only in PostTyper (to avoid cycles), which means we might get into situations where we coming a higher-kinded type in a union or intersection, which is illegal. In this case we now diagnose the problem with a TypeError instead of failing an assert. However, after Typer we do fail since by then such situations should have been checked by then. Fixeds scala#16696
Compiler version
3.2.1
Minimized code
https://scastie.scala-lang.org/VEozYp5OQlmLyTb0hn3KQw
Output (click arrow to expand)
The text was updated successfully, but these errors were encountered: