aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Checking.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-04-22 14:52:34 +0200
committerMartin Odersky <odersky@gmail.com>2015-04-22 17:19:35 +0200
commit79958518b4f95b3dd8e34d543757034d181e4514 (patch)
tree1633ef8d9764fe9a1233c661288ecf5ccf1c6620 /src/dotty/tools/dotc/typer/Checking.scala
parent1d4e4a6d4784edfe1d2490de7ceff9d3c82d4d27 (diff)
downloaddotty-79958518b4f95b3dd8e34d543757034d181e4514.tar.gz
dotty-79958518b4f95b3dd8e34d543757034d181e4514.tar.bz2
dotty-79958518b4f95b3dd8e34d543757034d181e4514.zip
Roll some of FirstTransform functionaility into PostTyper
Everything that needs to be done before pickling moves to PostTyper. The idea is that we want to make Pickler come before FirstTransform.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Checking.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Checking.scala17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala
index b28afa6f2..148e31885 100644
--- a/src/dotty/tools/dotc/typer/Checking.scala
+++ b/src/dotty/tools/dotc/typer/Checking.scala
@@ -39,6 +39,23 @@ object Checking {
d"Type argument ${arg.tpe} does not conform to $which bound $bound ${err.whyNoMatchStr(arg.tpe, bound)}",
arg.pos)
+ /** Check that `tp` refers to a nonAbstract class
+ * and that the instance conforms to the self type of the created class.
+ */
+ def checkInstantiable(tp: Type, pos: Position)(implicit ctx: Context): Unit =
+ tp.underlyingClassRef(refinementOK = false) match {
+ case tref: TypeRef =>
+ val cls = tref.symbol
+ if (cls.is(AbstractOrTrait))
+ ctx.error(d"$cls is abstract; cannot be instantiated", pos)
+ if (!cls.is(Module)) {
+ val selfType = tp.givenSelfType.asSeenFrom(tref.prefix, cls.owner)
+ if (selfType.exists && !(tp <:< selfType))
+ ctx.error(d"$tp does not conform to its self type $selfType; cannot be instantiated")
+ }
+ case _ =>
+ }
+
/** A type map which checks that the only cycles in a type are F-bounds
* and that protects all F-bounded references by LazyRefs.
*/