diff options
author | odersky <odersky@gmail.com> | 2017-04-09 16:28:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-09 16:28:56 +0200 |
commit | b8bb34dd0ea68cfed09ed54604f659a787037d2d (patch) | |
tree | 3387b92f511c18fa91a8417b6b74a43d798e4a19 | |
parent | 4d76265fac7edafc2fcf29ce6873fdb252fbba0d (diff) | |
parent | b159489576fc7afdee5b2d93e9465dbc87f8069e (diff) | |
download | dotty-b8bb34dd0ea68cfed09ed54604f659a787037d2d.tar.gz dotty-b8bb34dd0ea68cfed09ed54604f659a787037d2d.tar.bz2 dotty-b8bb34dd0ea68cfed09ed54604f659a787037d2d.zip |
Merge pull request #2204 from dotty-staging/fix/i2201
Fix #2201: Less aggressive type application reduction for better inference
-rw-r--r-- | compiler/src/dotty/tools/dotc/core/TypeApplications.scala | 9 | ||||
-rw-r--r-- | tests/pos/i2201a.scala | 8 | ||||
-rw-r--r-- | tests/pos/i2201b.scala | 14 | ||||
-rw-r--r-- | tests/pos/i2201c.scala | 11 |
4 files changed, 39 insertions, 3 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/TypeApplications.scala b/compiler/src/dotty/tools/dotc/core/TypeApplications.scala index 23c3f96cc..94b726491 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeApplications.scala @@ -391,9 +391,12 @@ class TypeApplications(val self: Type) extends AnyVal { if (!args.exists(_.isInstanceOf[TypeBounds])) { val followAlias = Config.simplifyApplications && { dealiased.resType match { - case AppliedType(tyconBody, _) => - sameLength(dealiased.typeParams, tyconBody.typeParams) - // Reducing is safe for type inference, as kind arity of type constructor does not change + case AppliedType(tyconBody, dealiasedArgs) => + // Reduction should not affect type inference when it's + // just eta-reduction (ignoring variance annotations). + // See i2201*.scala for examples where more aggressive + // reduction would break type inference. + dealiased.paramRefs == dealiasedArgs case _ => false } } diff --git a/tests/pos/i2201a.scala b/tests/pos/i2201a.scala new file mode 100644 index 000000000..165f0a76e --- /dev/null +++ b/tests/pos/i2201a.scala @@ -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) +} diff --git a/tests/pos/i2201b.scala b/tests/pos/i2201b.scala new file mode 100644 index 000000000..4aafc0d28 --- /dev/null +++ b/tests/pos/i2201b.scala @@ -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) +} diff --git a/tests/pos/i2201c.scala b/tests/pos/i2201c.scala new file mode 100644 index 000000000..91f2529d9 --- /dev/null +++ b/tests/pos/i2201c.scala @@ -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) +} |