File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -71,10 +71,17 @@ object RefChecks {
71
71
}
72
72
}
73
73
74
- /** Check that self type of this class conforms to self types of parents */
75
- private def checkSelfType (clazz : Symbol )(implicit ctx : Context ): Unit = clazz.info match {
74
+ /** Check that final and sealed restrictions on class parents
75
+ * and that self type of this class conforms to self types of parents.
76
+ */
77
+ private def checkParents (clazz : Symbol )(implicit ctx : Context ): Unit = clazz.info match {
76
78
case cinfo : ClassInfo =>
77
79
for (parent <- cinfo.classParents) {
80
+ val pclazz = parent.classSymbol
81
+ if (pclazz.is(Final ))
82
+ ctx.error(d " cannot extend final $pclazz" , clazz.pos)
83
+ if (pclazz.is(Sealed ) && pclazz.associatedFile != clazz.associatedFile)
84
+ ctx.error(d " cannot extend sealed $pclazz in different compilation unit " , clazz.pos)
78
85
val pself = parent.givenSelfType.asSeenFrom(clazz.thisType, parent.classSymbol)
79
86
if (pself.exists && ! (cinfo.selfType <:< pself))
80
87
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 =>
768
775
override def transformTemplate (tree : Template )(implicit ctx : Context , info : TransformerInfo ) = {
769
776
val cls = ctx.owner
770
777
checkOverloadedRestrictions(cls)
771
- checkSelfType (cls)
778
+ checkParents (cls)
772
779
checkCompanionNameClashes(cls)
773
780
checkAllOverrides(cls)
774
781
checkAnyValSubclass(cls)
Original file line number Diff line number Diff line change
1
+ final class A
2
+ class B extends A
3
+ class C extends Option [Int ]
4
+
You can’t perform that action at this time.
0 commit comments