aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/typer/RefChecks.scala13
-rw-r--r--tests/neg/final-sealed.scala4
2 files changed, 14 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)
diff --git a/tests/neg/final-sealed.scala b/tests/neg/final-sealed.scala
new file mode 100644
index 000000000..017afd63b
--- /dev/null
+++ b/tests/neg/final-sealed.scala
@@ -0,0 +1,4 @@
+final class A
+class B extends A
+class C extends Option[Int]
+