Skip to content

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