aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-12-02 16:00:07 +0100
committerMartin Odersky <odersky@gmail.com>2015-12-06 16:09:21 +0100
commit73bf06b4735b8a74c99ed185e52ae3350181f426 (patch)
tree60320e0261ebc0eecf54e5aedf99311f762cef78 /src/dotty/tools
parent2abcd02d2a2067ba78430262664f5d3ab9b61d00 (diff)
downloaddotty-73bf06b4735b8a74c99ed185e52ae3350181f426.tar.gz
dotty-73bf06b4735b8a74c99ed185e52ae3350181f426.tar.bz2
dotty-73bf06b4735b8a74c99ed185e52ae3350181f426.zip
More uses of adaptIfHK
Also: fix EtaExpansion. Also: Add some debug code to Applications, awaiting further fixes.
Diffstat (limited to 'src/dotty/tools')
-rw-r--r--src/dotty/tools/dotc/core/TypeApplications.scala3
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala8
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala30
3 files changed, 21 insertions, 20 deletions
diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala
index b1ffe0169..618dd35e8 100644
--- a/src/dotty/tools/dotc/core/TypeApplications.scala
+++ b/src/dotty/tools/dotc/core/TypeApplications.scala
@@ -62,7 +62,6 @@ object TypeApplications {
def unapply(tp: Type)(implicit ctx: Context): Option[(List[Int], List[TypeBounds], Type)] = tp match {
case app @ RefinedType(prefix, tpnme.hkApply) =>
- println(s"type lam $tp")
val cls = prefix.typeSymbol
val variances = cls.typeParams.map(_.variance)
val argBounds = prefix.argInfos.map(_.bounds)
@@ -89,7 +88,7 @@ object TypeApplications {
val tparams = tycon.typeParams
val variances = tycon.typeParams.map(_.variance)
TypeLambda(tparams.map(_.variance), tycon.paramBounds,
- rt => tycon.appliedTo(tparams.map(RefinedThis(rt).select(_))))
+ rt => tycon.appliedTo(argRefs(rt, tparams.length)))
}
def unapply(tp: Type)(implicit ctx: Context): Option[TypeRef] = {
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index 4ca9c39af..e8ba3b07b 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -613,8 +613,12 @@ trait Applications extends Compatibility { self: Typer =>
assignType(cpy.TypeApply(tree)(typedFn, typedArgs), typedFn, typedArgs)
}
- def adaptTypeArg(tree: tpd.Tree, bound: Type)(implicit ctx: Context): tpd.Tree =
- tree.withType(tree.tpe.EtaExpandIfHK(bound))
+ def adaptTypeArg(tree: tpd.Tree, bound: Type)(implicit ctx: Context): tpd.Tree = {
+ val was = tree.tpe.EtaExpandIfHK(bound)
+ //val now = tree.tpe.adaptIfHK(bound) // ###
+ //if (was != now) println(i"diff adapt ${tree.tpe} to $bound, was: $was, now: $now")
+ tree.withType(was)//tree.tpe.adaptIfHK(bound))
+ }
/** Rewrite `new Array[T](....)` trees to calls of newXYZArray methods. */
def convertNewArray(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match {
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index 5eebdbad1..eecbd1347 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -18,6 +18,7 @@ import config.Printers._
import Annotations._
import Inferencing._
import transform.ValueClasses._
+import TypeApplications._
import language.implicitConversions
trait NamerContextOps { this: Context =>
@@ -840,26 +841,23 @@ class Namer { typer: Typer =>
/** Eta expand all class types C appearing as arguments to a higher-kinded
* type parameter to type lambdas, e.g. [HK0] => C[HK0]. This is necessary
- * because in `typedAppliedTypeTree` we might ahve missed some eta expansions
+ * because in `typedAppliedTypeTree` we might have missed some eta expansions
* of arguments in F-bounds, because the recursive type was initialized with
* TypeBounds.empty.
*/
+ // ### Check whether this is still needed!
def etaExpandArgs(implicit ctx: Context) = new TypeMap {
- def apply(tp: Type): Type = {
- tp match {
- case tp: RefinedType =>
- val args = tp.argInfos.mapconserve(this)
- if (args.nonEmpty) {
- val tycon = tp.withoutArgs(args)
- val tparams = tycon.typeParams
- if (args.length == tparams.length) { // if lengths differ, problem is caught in typedTypeApply
- val args1 = args.zipWithConserve(tparams)((arg, tparam) => arg.EtaExpandIfHK(tparam.info))
- if (args1 ne args) return this(tycon).appliedTo(args1)
- }
- }
- case _ =>
- }
- mapOver(tp)
+ def apply(tp: Type): Type = tp match {
+ case tp: RefinedType =>
+ val args = tp.argInfos.mapconserve(this)
+ if (args.nonEmpty) {
+ val tycon = tp.withoutArgs(args)
+ val tycon1 = this(tycon)
+ val tparams = tycon.typeParams
+ val args1 = if (args.length == tparams.length) adaptArgs(tparams, args) else args
+ if ((tycon1 eq tycon) && (args1 eq args)) tp else tycon1.appliedTo(args1)
+ } else mapOver(tp)
+ case _ => mapOver(tp)
}
}
}