aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Checking.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-06-11 19:09:06 +0200
committerMartin Odersky <odersky@gmail.com>2015-06-19 12:11:18 +0200
commit8c28293fd52213616ed8ca3a2f600eb1e19debe0 (patch)
treea07d7d0116530ab19e71e5909433df439b57f7a2 /src/dotty/tools/dotc/typer/Checking.scala
parent065a0b4c9cb34b448e070a80e4ad4af9e5ade20a (diff)
downloaddotty-8c28293fd52213616ed8ca3a2f600eb1e19debe0.tar.gz
dotty-8c28293fd52213616ed8ca3a2f600eb1e19debe0.tar.bz2
dotty-8c28293fd52213616ed8ca3a2f600eb1e19debe0.zip
Implement checking for illegal parent trait constructor calls.
A parent trait may not be parameterized (as in T()) if the calling class does not directly implement that trait.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Checking.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Checking.scala14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala
index 3ef6d059a..9047b8cb3 100644
--- a/src/dotty/tools/dotc/typer/Checking.scala
+++ b/src/dotty/tools/dotc/typer/Checking.scala
@@ -20,6 +20,7 @@ import annotation.unchecked
import util.Positions._
import util.{Stats, SimpleMap}
import util.common._
+import transform.SymUtils._
import Decorators._
import Uniques._
import ErrorReporting.{err, errorType, DiagnosticString}
@@ -328,9 +329,15 @@ trait Checking {
}
}
- def checkInstantiatable(cls: ClassSymbol, pos: Position): Unit = {
- ??? // to be done in later phase: check that class `cls` is legal in a new.
- }
+ def checkParentCall(call: Tree, caller: ClassSymbol)(implicit ctx: Context) =
+ if (!ctx.isAfterTyper) {
+ val called = call.tpe.classSymbol
+ if (caller is Trait)
+ ctx.error(i"$caller may not call constructor of $called", call.pos)
+ else if (called.is(Trait) && !caller.mixins.contains(called))
+ ctx.error(i"""$called is already implemented by super${caller.superClass},
+ |its constructor cannot be called again""".stripMargin, call.pos)
+ }
}
trait NoChecking extends Checking {
@@ -343,4 +350,5 @@ trait NoChecking extends Checking {
override def checkImplicitParamsNotSingletons(vparamss: List[List[ValDef]])(implicit ctx: Context): Unit = ()
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) = ()
}