Skip to content

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