Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix improper usage of
constrained
breaking type inference
In multiple places, we had code equivalent to the following pattern: val (tl2, targs) = constrained(tl) tl2.resultType <:< ... which lead to subtype checks directly involving the TypeParamRefs of the constrained type lambda. This commit uses the following pattern instead: val (tl2, targs) = constrained(tl) tl2.instantiate(targs.map(_.tpe)) <:< ... which substitutes the TypeParamRefs by the corresponding TypeVars in the constraint. This is necessary because when comparing TypeParamRefs in isSubType: - we only recurse on the bounds of the TypeParamRef using `isSubTypeWhenFrozen` which prevents further constraints from being added (see the added stm.scala test case for an example where this matters). - if the corresponding TypeVar is instantiated and the TyperState has been gc()'ed, there is no way to find the instantiation corresponding to the current TypeParamRef anymore. There is one place where I left the old logic intact: `TrackingTypeComparer#matchCase` because the match type caching logic (in `MatchType#reduced`) conflicted with the use of TypeVars since it retracts the current TyperState.
- Loading branch information
Showing
4 changed files
with
25 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Inv[X] | ||
class Ref[X] | ||
object Ref { | ||
def apply(i: Inv[Int], x: Int): Ref[Int] = ??? | ||
def apply[Y](i: Inv[Y], x: Y): Ref[Y] = ??? | ||
} | ||
|
||
class A { | ||
val ref: Ref[List[AnyRef]] = Ref(new Inv[List[AnyRef]], List.empty) | ||
} |