-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #4032: Fix direction of instantiation.
Intrepolation is a pretty delicate scenario. It's difficult to even say what is right and what is wrong. In #4032 there's an unconstrained type variable that should be interpolated and it's a coin flip whether we instantiate it to the lower or upper bound. A completely unrelated change in #3981 meant that we instantiated the variable to the upper instead of the lower bound which caused the program to fail. The failure was because the type variable appeared covariantly in the lower bound of some other type variable. So maximizing the type first type variable overconstrained the second. We avoid this problem now by computing the variance of the type variable that's eliminated in the rest of the constraint. We take this into account to instantiate the variable so that it narrows the overall constraint the least, defaulting again to lower bound if there is not best direction. Since the test is expensive (linear in the constraint size), we do this only if the variable's lower bound is unconstrained. We could do it for all non-occurring type variables, but have to see how that would affect performance.
- Loading branch information
Showing
3 changed files
with
47 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import scala.concurrent.Future | ||
|
||
class Gen[+T] { | ||
def map[U](f: T => U): Gen[U] = ??? | ||
} | ||
|
||
object Gen { | ||
def oneOf[T](t0: T, t1: T): Gen[T] = ??? // Compile with this line commented | ||
def oneOf[T](g0: Gen[T], g1: Gen[T]): Gen[T] = ??? | ||
} | ||
|
||
class Arbitrary[T] | ||
|
||
object Arbitrary { | ||
def arbitrary[T]: Gen[T] = ??? | ||
|
||
def arbFuture[X]: Gen[Future[X]] = | ||
Gen.oneOf(arbitrary[Future[X]], arbitrary[Throwable].map(Future.failed)) | ||
} |