aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/TypeApplications.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-07-13 13:46:54 +0200
committerMartin Odersky <odersky@gmail.com>2016-07-13 13:47:44 +0200
commitf50cb2040494e622f17a1bcc323424a27129fc3a (patch)
tree34c77552d3b6f6b25797ba66494e679427dd35a2 /src/dotty/tools/dotc/core/TypeApplications.scala
parent1443fd4c844c1c54e59479e156833d2cce9a349a (diff)
downloaddotty-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/TypeApplications.scala')
-rw-r--r--src/dotty/tools/dotc/core/TypeApplications.scala28
1 files changed, 13 insertions, 15 deletions
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.
*/