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/Types.scala | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/dotty/tools/dotc/core/Types.scala') diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index fc68740eb..d1e5ba47d 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -3422,8 +3422,9 @@ object Types { case tp: HKApply => def mapArg(arg: Type, tparam: TypeParamInfo): Type = { val saved = variance - if (tparam.paramVariance < 0) variance = -variance - else if (tparam.paramVariance == 0) variance = 0 + val pvariance = tparam.paramVariance + if (pvariance < 0) variance = -variance + else if (pvariance == 0) variance = 0 try this(arg) finally variance = saved } @@ -3629,7 +3630,23 @@ object Types { this(x, prefix) case tp @ HKApply(tycon, args) => - foldOver(this(x, tycon), args) + def foldArgs(x: T, tparams: List[TypeParamInfo], args: List[Type]): T = + if (args.isEmpty) { + assert(tparams.isEmpty) + x + } + else { + val tparam = tparams.head + val saved = variance + val pvariance = tparam.paramVariance + if (pvariance < 0) variance = -variance + else if (pvariance == 0) variance = 0 + val acc = + try this(x, args.head) + finally variance = saved + foldArgs(acc, tparams.tail, args.tail) + } + foldArgs(this(x, tycon), tp.typeParams, args) case tp: AndOrType => this(this(x, tp.tp1), tp.tp2) -- cgit v1.2.3