From b159489576fc7afdee5b2d93e9465dbc87f8069e Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Sat, 8 Apr 2017 22:51:16 +0200 Subject: Fix #2201: Less aggressive type application reduction for better inference 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] --- compiler/src/dotty/tools/dotc/core/TypeApplications.scala | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'compiler/src/dotty/tools/dotc') 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 } } -- cgit v1.2.3