-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #2201: Less aggressive type application reduction for better infe…
…rence Previously we believed that reducing type applications did not affect type inference as long as the reduced type constructor had the same arity as the unreduced one, for example reducing `Foo[X, Y]` is fine when `Foo` is defined as: type Foo[A, B] = Bar[A, B] but not when it's defined as: type Foo[A] = Bar[A, A] But this is not a sufficient condition: the bounds of the type constructor arguments also matter for type inference, so we need to be more strict and disallow reductions in cases like: type Foo[A, B] = Bar[B, A] and: type Foo[A, B] = Bar[A, Int]
- Loading branch information
Showing
4 changed files
with
39 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Foo[T] | ||
|
||
class Fix[F[_]](unfix: F[Fix[F]]) | ||
object DocTree { | ||
type Const[T] = Foo[Int] | ||
type FixConst = Fix[Const] | ||
def docTree(s: Const[FixConst]): FixConst = new Fix(s) | ||
} |
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,14 @@ | ||
trait X | ||
trait Y | ||
|
||
object Test { | ||
type One[A <: X, B <: Y] | ||
|
||
type Two[TA <: Y, TB <: X] = One[TB, TA] | ||
|
||
def foo[M[_ <: Y, _ <: X]](x: M[_ <: Y, _ <: X]) = x | ||
|
||
val a: Two[Y, X] = ??? | ||
|
||
foo(a) | ||
} |
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,11 @@ | ||
object Test { | ||
implicit val theAnswer: Int = 42 | ||
|
||
type Swap[A, B] = (B, A) | ||
|
||
def foo[M[_, _], T, S](x: M[T, S])(implicit ev: T) = ev | ||
|
||
val a: Swap[Int, String] = ("hi", 1) | ||
|
||
foo(a) | ||
} |