-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #2771: pre-check kinds at Typer #2882
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
Conversation
After adding star-kind-checking, t3683-modified.scala caused a crash because an ErrorType ended up as the type of a type parameter but a TypeBounds was required. This was possible due to the unsafe cast in LambdaTypeCompanion.fromParams, which this commit eliminates.
We need to take DerivedTypeTrees into account when computing the type parameters of a type completer.
Fix problems in previous iteration.
While this PR helps avoid some absurd applications, I don't think it solves the fundamental issue where a type can be seen as having multiple kinds because of bad bounds, here's a slightly modified test case that causes a stackoverflow while beta-reducing: trait A { type L[X[_]] }
trait B { type L }
trait C { type M <: A }
trait D { type M >: B }
object Test {
def test(x: C with D): Unit = {
def f(y: x.M)(z: y.L[y.L]) = z
f(new B { type L[F[_[_]]] = F[F] })(1)
}
} |
We now check that the rank of the kind of a type argument does not exceed the rank of its bounds. i2771b is an example that shows that checking at rank * only is not enough.
Previous way of taking the result type was too naive.
Need to also check parameter kinds of higher-kinded types, not just result kinds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM because I can't break it anymore :) (maybe @sstucki can?). It'd be nice to give more detailed error messages (instead of just saying "has wrong kind", say what the actual and expected kinds are), but we can address that separately.
Found a way to break the fixed version, though the error is different. See #2887. |
We normally do kind checking during PostTyper, together with bounds checking.
However, this is not early enough, as #2771 shows. The problem is that we can
use ill-kinded code to construct self applications of types, which leads to general
unhappiness in the typer. Prevent that by checking the outline of kinds of types
as soon as we create them.