Skip to content
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

Fix widening logic to keep instantiation within bounds #16417

Merged
merged 1 commit into from
Nov 28, 2022

Conversation

smarter
Copy link
Member

@smarter smarter commented Nov 25, 2022

Before this commit, if Config.checkConstraintsSatisfiable was set to true, then tests/pos/cls.scala would fail on val b1 with:

Y is constrained to be  >: Matchable but attempted to instantiate it to Int | String

This happens because when widenInferred widens a union, it constrains the upper-bound of the parameter being instantiated to be a subtype of that union (tpw <:< bound). This is usually fine, but if isTransparent is true, we'll return the original unwidened type, which is now out of bounds.

To avoid this inconsistency, the isTransparent check is now moved before the subtype check that updates the bounds.

Before this commit, if `Config.checkConstraintsSatisfiable` was set to `true`,
then tests/pos/cls.scala would fail on `val b1` with:

    Y is constrained to be  >: Matchable but attempted to instantiate it to Int | String

This happens because when `widenInferred` widens a union, it constrains the
upper-bound of the parameter being instantiated to be a subtype of that union
(`tpw <:< bound`). This is usually fine, but if `isTransparent` is true, we'll
return the original unwidened type, which is now out of bounds.

To avoid this inconsistency, the `isTransparent` check is now moved before the
subtype check that updates the bounds.
@odersky odersky merged commit 1b3a52c into scala:main Nov 28, 2022
@odersky odersky deleted the inst-in-bounds branch November 28, 2022 14:50
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