aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/RefChecks.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-07-02 14:02:25 +0200
committerMartin Odersky <odersky@gmail.com>2015-07-02 14:02:42 +0200
commit983875084b103f9d46749372c750ff71bf139181 (patch)
treeb4ba8c9474506572b5100e29591c824b639fb693 /src/dotty/tools/dotc/typer/RefChecks.scala
parent3512840ca6389898fa38c86282dd4c6671ba6863 (diff)
downloaddotty-983875084b103f9d46749372c750ff71bf139181.tar.gz
dotty-983875084b103f9d46749372c750ff71bf139181.tar.bz2
dotty-983875084b103f9d46749372c750ff71bf139181.zip
Check final and sealed conditions
So far no error was raised for illegal inheritance from final or sealed classes.
Diffstat (limited to 'src/dotty/tools/dotc/typer/RefChecks.scala')
-rw-r--r--src/dotty/tools/dotc/typer/RefChecks.scala13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/typer/RefChecks.scala b/src/dotty/tools/dotc/typer/RefChecks.scala
index 3633a7279..d9b62badc 100644
--- a/src/dotty/tools/dotc/typer/RefChecks.scala
+++ b/src/dotty/tools/dotc/typer/RefChecks.scala
@@ -71,10 +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 {
+ /** Check that final and sealed restrictions on class parents
+ * and that self type of this class conforms to self types of parents.
+ */
+ private def checkParents(clazz: Symbol)(implicit ctx: Context): Unit = clazz.info match {
case cinfo: ClassInfo =>
for (parent <- cinfo.classParents) {
+ val pclazz = parent.classSymbol
+ if (pclazz.is(Final))
+ ctx.error(d"cannot extend final $pclazz", clazz.pos)
+ if (pclazz.is(Sealed) && pclazz.associatedFile != clazz.associatedFile)
+ ctx.error(d"cannot extend sealed $pclazz in different compilation unit", clazz.pos)
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)
@@ -768,7 +775,7 @@ class RefChecks extends MiniPhase { thisTransformer =>
override def transformTemplate(tree: Template)(implicit ctx: Context, info: TransformerInfo) = {
val cls = ctx.owner
checkOverloadedRestrictions(cls)
- checkSelfType(cls)
+ checkParents(cls)
checkCompanionNameClashes(cls)
checkAllOverrides(cls)
checkAnyValSubclass(cls)