Skip to content

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

Merged
merged 9 commits into from
Jul 18, 2017
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jul 17, 2017

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.

odersky added 5 commits July 17, 2017 13:42
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.
@odersky odersky changed the title Fix #2771: Check for star kinds early Fix #2771: Check for * kinds early Jul 17, 2017
@smarter
Copy link
Member

smarter commented Jul 17, 2017

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.
odersky added 3 commits July 18, 2017 10:46
Previous way of taking the result type was too naive.
Need to also check parameter kinds of higher-kinded types,
not just result kinds.
@odersky odersky requested a review from smarter July 18, 2017 11:35
@odersky odersky changed the title Fix #2771: Check for * kinds early Fix #2771: pre-check kinds at Typer Jul 18, 2017
Copy link
Member

@smarter smarter left a 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.

@odersky odersky merged commit 775e3db into scala:master Jul 18, 2017
@sstucki
Copy link
Contributor

sstucki commented Jul 18, 2017

Found a way to break the fixed version, though the error is different. See #2887.

@allanrenucci allanrenucci deleted the fix-#2770 branch December 14, 2017 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants