aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/RefChecks.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-04-12 18:05:11 +0200
committerMartin Odersky <odersky@gmail.com>2015-04-13 16:05:12 +0200
commit04eea24326c3a42ad908fe45e204af41b880f2cd (patch)
tree54ef40e919a1a4c1df25f0872c998979f4135811 /src/dotty/tools/dotc/typer/RefChecks.scala
parentd4dc78c3ebe4e8b559c3a85b6b77c321b239bb90 (diff)
downloaddotty-04eea24326c3a42ad908fe45e204af41b880f2cd.tar.gz
dotty-04eea24326c3a42ad908fe45e204af41b880f2cd.tar.bz2
dotty-04eea24326c3a42ad908fe45e204af41b880f2cd.zip
Self type inheritance check
Check that the self type of a class conforms to the self types of its parent classes.
Diffstat (limited to 'src/dotty/tools/dotc/typer/RefChecks.scala')
-rw-r--r--src/dotty/tools/dotc/typer/RefChecks.scala12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/typer/RefChecks.scala b/src/dotty/tools/dotc/typer/RefChecks.scala
index 9b14fffc0..6a1f3652b 100644
--- a/src/dotty/tools/dotc/typer/RefChecks.scala
+++ b/src/dotty/tools/dotc/typer/RefChecks.scala
@@ -71,6 +71,17 @@ object RefChecks {
}
}
+ /** Check that self type of this class conforms to self types of parents */
+ private def checkSelfType(clazz: Symbol)(implicit ctx: Context): Unit = clazz.info match {
+ case cinfo: ClassInfo =>
+ for (parent <- cinfo.classParents) {
+ val pself = parent.givenSelfType.asSeenFrom(clazz.thisType, parent.classSymbol)
+ if (pself.exists && !(cinfo.selfType <:< pself))
+ ctx.error(d"illegal inheritance: self type ${cinfo.selfType} of $clazz does not conform to self type $pself of parent ${parent.classSymbol}", clazz.pos)
+ }
+ case _ =>
+ }
+
// Override checking ------------------------------------------------------------
/** 1. Check all members of class `clazz` for overriding conditions.
@@ -770,6 +781,7 @@ class RefChecks extends MiniPhase with SymTransformer { thisTransformer =>
override def transformTemplate(tree: Template)(implicit ctx: Context, info: TransformerInfo) = {
val cls = ctx.owner
checkOverloadedRestrictions(cls)
+ checkSelfType(cls)
checkAllOverrides(cls)
checkAnyValSubclass(cls)
tree