From fd44a171340a87359e267aeb63072bc5a8873b10 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 11 Dec 2015 09:56:40 +0100 Subject: Disallow hk type parameters in lower bounds. Also: various cleanups to comments. --- src/dotty/tools/dotc/core/TypeComparer.scala | 4 ++-- src/dotty/tools/dotc/typer/Applications.scala | 6 +----- src/dotty/tools/dotc/typer/Checking.scala | 12 ++++++++++++ src/dotty/tools/dotc/typer/Namer.scala | 1 - src/dotty/tools/dotc/typer/Typer.scala | 1 + 5 files changed, 16 insertions(+), 8 deletions(-) (limited to 'src') 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) -- cgit v1.2.3