From f50cb2040494e622f17a1bcc323424a27129fc3a Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 13 Jul 2016 13:46:54 +0200 Subject: Make rewritings of hk applications configurable Beta-reduce only if `Config.simplifyApplications` is true. Turning off beta-reduction revealed two problems which are also fixed in this commit: 1. Bad treatement of higher-kinded argyments in cyclicity checking 2. Wrong variance for higher-kinded arguments in TypeAccumulator --- src/dotty/tools/dotc/core/TypeApplications.scala | 28 +++++++++++------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'src/dotty/tools/dotc/core/TypeApplications.scala') diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index b9957ccb2..db6020e54 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -469,18 +469,21 @@ class TypeApplications(val self: Type) extends AnyVal { case dealiased: TypeLambda => def tryReduce = if (!args.exists(_.isInstanceOf[TypeBounds])) { - val reduced = dealiased.instantiate(args) - if (dealiased eq stripped) reduced - else reduced match { - case AppliedType(tycon, args) if variancesConform(typParams, tycon.typeParams) => - // Reducing is safe for type inference, as kind of type constructor does not change - //println(i"reduced: $reduced instead of ${HKApply(self, args)}") - reduced + val followAlias = stripped match { + case stripped: TypeRef => + stripped.symbol.is(BaseTypeArg) case _ => - // Reducing changes kind, keep hk application instead - //println(i"fallback: ${HKApply(self, args)} instead of $reduced") - HKApply(self, args) + Config.simplifyApplications && { + dealiased.resType match { + case AppliedType(tyconBody, _) => + variancesConform(typParams, tyconBody.typeParams) + // Reducing is safe for type inference, as kind of type constructor does not change + case _ => false + } + } } + if ((dealiased eq stripped) || followAlias) dealiased.instantiate(args) + else HKApply(self, args) } else dealiased.resType match { case AppliedType(tycon, args1) if tycon.safeDealias ne tycon => @@ -665,11 +668,6 @@ class TypeApplications(val self: Type) extends AnyVal { } } - final def typeConstructor(implicit ctx: Context): Type = self.stripTypeVar match { - case AppliedType(tycon, _) => tycon - case self => self - } - /** If this is the image of a type argument; recover the type argument, * otherwise NoType. */ -- cgit v1.2.3