Skip to content

Fix #8976: Do not instantiate type variables outside bounds #9010

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

Closed
wants to merge 2 commits into from

Conversation

odersky
Copy link
Contributor

@odersky odersky commented May 20, 2020

Avoid instantiations of type variables that do not fit their bounds. Throw a TypeError instead.

@odersky odersky changed the title Fix #8976: Avoid instantiations of type variables that do not fit the… Fix #8976: Do not instantiate type variables outside bounds May 20, 2020
Using <:< leads to a non-terminating or very long compile when compiling
scalatest
Comment on lines +4221 to +4224
* - It is checked that the resulting type still fits within
* bounds. If not, a `NoInstance` exception is thrown,
* but only after instantiating the variable anyway because
* this avoids follow-on errors.
Copy link
Member

@smarter smarter May 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced this is needed:

  • avoidCaptures already checks that the approximation is within bound and throws an exception if it isn't
  • widenInferred will not do any widening if that would be out of bounds

The only problematic piece is approximation in ConstraintHandling which will replace recursive occurences of the type variable being instantiated by TypeBounds.empty, which can indeed be unsound. Here's an alternative PR which tries to fix that specific problem: #9012

@odersky
Copy link
Contributor Author

odersky commented May 20, 2020

Closed in favor of #9012

@odersky odersky closed this May 20, 2020
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.

2 participants