diff options
author | Martin Odersky <odersky@gmail.com> | 2016-07-13 13:46:54 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-07-13 13:47:44 +0200 |
commit | f50cb2040494e622f17a1bcc323424a27129fc3a (patch) | |
tree | 34c77552d3b6f6b25797ba66494e679427dd35a2 /src/dotty/tools/dotc/core/Types.scala | |
parent | 1443fd4c844c1c54e59479e156833d2cce9a349a (diff) | |
download | dotty-f50cb2040494e622f17a1bcc323424a27129fc3a.tar.gz dotty-f50cb2040494e622f17a1bcc323424a27129fc3a.tar.bz2 dotty-f50cb2040494e622f17a1bcc323424a27129fc3a.zip |
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
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 23 |
1 files changed, 20 insertions, 3 deletions
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) |