aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-12-11 09:56:40 +0100
committerMartin Odersky <odersky@gmail.com>2015-12-11 10:06:14 +0100
commitfd44a171340a87359e267aeb63072bc5a8873b10 (patch)
tree45bf12dbad8d185ba69fd37fc5440d01bce3b591 /src/dotty/tools/dotc
parent1c77b03cb9909c3a1bf4477e49e58d81b25f47b2 (diff)
downloaddotty-fd44a171340a87359e267aeb63072bc5a8873b10.tar.gz
dotty-fd44a171340a87359e267aeb63072bc5a8873b10.tar.bz2
dotty-fd44a171340a87359e267aeb63072bc5a8873b10.zip
Disallow hk type parameters in lower bounds.
Also: various cleanups to comments.
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala4
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala6
-rw-r--r--src/dotty/tools/dotc/typer/Checking.scala12
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala1
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala1
5 files changed, 16 insertions, 8 deletions
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index 866c01126..bf82bfe09 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -550,7 +550,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
*
* (2) Try to eta expand the constructor of `other`.
*
- * (3a) In mode `TypeVarsMissConetxt` replace the projection's hk constructor parameter
+ * (3a) In mode `TypevarsMissConetxt` replace the projection's hk constructor parameter
* by the eta expansion of step (2) reapplied to the projection's arguments.
* (3b) In normal mode, try to unify the projection's hk constructor parameter with
* the eta expansion of step(2)
@@ -573,7 +573,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
else
(tryInstantiate(param, EtaExpansion(tycon)), projection)
ok &&
- (if (inOrder) isSubType(projection1, other) else isSubType(other, projection1)) // ### move out?
+ (if (inOrder) isSubType(projection1, other) else isSubType(other, projection1))
case _ =>
false
}
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index d119658be..c6053d0fd 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -613,12 +613,8 @@ 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 = {
- //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")
+ def adaptTypeArg(tree: tpd.Tree, bound: Type)(implicit ctx: Context): tpd.Tree =
tree.withType(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/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala
index 9dfe46232..57032c4d9 100644
--- a/src/dotty/tools/dotc/typer/Checking.scala
+++ b/src/dotty/tools/dotc/typer/Checking.scala
@@ -401,6 +401,17 @@ trait Checking {
errorTree(tpt, d"missing type parameter for ${tpt.tpe}")
}
else tpt
+
+ def checkLowerNotHK(sym: Symbol, tparams: List[Symbol], pos: Position)(implicit ctx: Context) =
+ if (tparams.nonEmpty)
+ sym.info match {
+ case info: TypeAlias => // ok
+ case TypeBounds(lo, _) =>
+ for (tparam <- tparams)
+ if (tparam.typeRef.occursIn(lo))
+ ctx.error(i"type parameter ${tparam.name} may not occur in lower bound $lo", pos)
+ case _ =>
+ }
}
trait NoChecking extends Checking {
@@ -414,4 +425,5 @@ trait NoChecking extends Checking {
override def checkNoDoubleDefs(cls: Symbol)(implicit ctx: Context): Unit = ()
override def checkParentCall(call: Tree, caller: ClassSymbol)(implicit ctx: Context) = ()
override def checkSimpleKinded(tpt: Tree)(implicit ctx: Context): Tree = tpt
+ override def checkLowerNotHK(sym: Symbol, tparams: List[Symbol], pos: Position)(implicit ctx: Context) = ()
}
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index eecbd1347..fedbc98b8 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -845,7 +845,6 @@ class Namer { typer: Typer =>
* 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 =>
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 0d7db4f9a..08ed04286 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -930,6 +930,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
def typedTypeDef(tdef: untpd.TypeDef, sym: Symbol)(implicit ctx: Context): Tree = track("typedTypeDef") {
val TypeDef(name, rhs) = tdef
+ checkLowerNotHK(sym, tdef.tparams.map(symbolOfTree), tdef.pos)
completeAnnotations(tdef, sym)
val _ = typedType(rhs) // unused, typecheck only to remove from typedTree
assignType(cpy.TypeDef(tdef)(name, TypeTree(sym.info), Nil), sym)