diff options
author | Dmitry Petrashko <dark@d-d.me> | 2015-10-20 11:19:24 +0200 |
---|---|---|
committer | Dmitry Petrashko <dark@d-d.me> | 2015-10-20 11:19:24 +0200 |
commit | cbb565a436196b102c27688d1da8f27bea12bae4 (patch) | |
tree | bd2501c2a074ed75b2a10a2b87e17b3d8f272267 | |
parent | 78d769004bdcd152f9f4816bb5cf699aeeb73ff3 (diff) | |
parent | 6cca64fa0aa37942812d1c870b99f309dab67352 (diff) | |
download | dotty-cbb565a436196b102c27688d1da8f27bea12bae4.tar.gz dotty-cbb565a436196b102c27688d1da8f27bea12bae4.tar.bz2 dotty-cbb565a436196b102c27688d1da8f27bea12bae4.zip |
Merge pull request #821 from dotty-staging/fix-check-simple-kinded
Check that some types are not higher-kinded.
-rw-r--r-- | src/dotty/tools/dotc/typer/Checking.scala | 13 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 6 | ||||
-rw-r--r-- | test/dotc/tests.scala | 2 | ||||
-rw-r--r-- | tests/neg/typers.scala | 8 | ||||
-rw-r--r-- | tests/pos/polyalias.scala | 2 |
5 files changed, 25 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala index 9092523db..8f4a8b72b 100644 --- a/src/dotty/tools/dotc/typer/Checking.scala +++ b/src/dotty/tools/dotc/typer/Checking.scala @@ -16,6 +16,7 @@ import Trees._ import ProtoTypes._ import Constants._ import Scopes._ +import ErrorReporting.errorTree import annotation.unchecked import util.Positions._ import util.{Stats, SimpleMap} @@ -347,6 +348,17 @@ trait Checking { ctx.error(i"""$called is already implemented by super${caller.superClass}, |its constructor cannot be called again""".stripMargin, call.pos) } + + /** Check that `tpt` does not define a higher-kinded type */ + def checkSimpleKinded(tpt: Tree)(implicit ctx: Context): Tree = + if (tpt.tpe.isHK && !ctx.compilationUnit.isJava) { + // be more lenient with missing type params in Java, + // needed to make pos/java-interop/t1196 work. + val alias = tpt.tpe.dealias + if (alias.isHK) errorTree(tpt, d"missing type parameter for ${tpt.tpe}") + else tpt.withType(alias) + } + else tpt } trait NoChecking extends Checking { @@ -360,4 +372,5 @@ trait NoChecking extends Checking { override def checkFeasible(tp: Type, pos: Position, where: => String = "")(implicit ctx: Context): Type = tp 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 } diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 1bd4152e9..fbdfef930 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -370,7 +370,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit if (untpd.isWildcardStarArg(tree)) TypeTree(defn.SeqClass.typeRef.appliedTo(pt :: Nil)) else - typedType(tree.tpt) + checkSimpleKinded(typedType(tree.tpt)) val expr1 = if (isWildcard) tree.expr withType tpt1.tpe else typed(tree.expr, tpt1.tpe) @@ -918,7 +918,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def typedValDef(vdef: untpd.ValDef, sym: Symbol)(implicit ctx: Context) = track("typedValDef") { val ValDef(name, tpt, _) = vdef completeAnnotations(vdef, sym) - val tpt1 = typedType(tpt) + val tpt1 = checkSimpleKinded(typedType(tpt)) val rhs1 = vdef.rhs match { case rhs @ Ident(nme.WILDCARD) => rhs withType tpt1.tpe case rhs => typedExpr(rhs, tpt1.tpe) @@ -932,7 +932,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit val tparams1 = tparams mapconserve (typed(_).asInstanceOf[TypeDef]) val vparamss1 = vparamss nestedMapconserve (typed(_).asInstanceOf[ValDef]) if (sym is Implicit) checkImplicitParamsNotSingletons(vparamss1) - val tpt1 = typedType(tpt) + val tpt1 = checkSimpleKinded(typedType(tpt)) val rhs1 = typedExpr(ddef.rhs, tpt1.tpe) assignType(cpy.DefDef(ddef)(name, tparams1, vparamss1, tpt1, rhs1), sym) //todo: make sure dependent method types do not depend on implicits or by-name params diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index cf213033d..89687d16c 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -105,7 +105,7 @@ class tests extends CompilerTest { @Test def neg_typedapply() = compileFile(negDir, "typedapply", xerrors = 4) @Test def neg_typedidents() = compileFile(negDir, "typedIdents", xerrors = 2) @Test def neg_assignments() = compileFile(negDir, "assignments", xerrors = 3) - @Test def neg_typers() = compileFile(negDir, "typers", xerrors = 10)(allowDoubleBindings) + @Test def neg_typers() = compileFile(negDir, "typers", xerrors = 13)(allowDoubleBindings) @Test def neg_privates() = compileFile(negDir, "privates", xerrors = 2) @Test def neg_rootImports = compileFile(negDir, "rootImplicits", xerrors = 2) @Test def neg_templateParents() = compileFile(negDir, "templateParents", xerrors = 3) diff --git a/tests/neg/typers.scala b/tests/neg/typers.scala index 9fcc63e38..8bd39a557 100644 --- a/tests/neg/typers.scala +++ b/tests/neg/typers.scala @@ -29,8 +29,14 @@ object typers { def g[T](x: T): T = x // OK! } + type L[X] = scala.collection.immutable.List[X] + type M[X, Y] <: scala.collection.immutable.Map[X, Y] - + object hk { + def f(x: L) // error: missing type parameter + : M = // error: missing type parameter + ??? : M // error: missing type parameter + } object returns { diff --git a/tests/pos/polyalias.scala b/tests/pos/polyalias.scala index 07bb241f0..6ce0e3230 100644 --- a/tests/pos/polyalias.scala +++ b/tests/pos/polyalias.scala @@ -3,7 +3,7 @@ object Test { type S = scala.Predef.Set - val z: S = ??? + val z: S[_] = ??? type Pair[T] = (T, T) |