File tree Expand file tree Collapse file tree 3 files changed +15
-10
lines changed
src/dotty/tools/dotc/typer Expand file tree Collapse file tree 3 files changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -666,6 +666,8 @@ class Namer { typer: Typer =>
666
666
* (1) It must be a class type with a stable prefix (@see checkClassTypeWithStablePrefix)
667
667
* (2) If may not derive from itself
668
668
* (3) Overriding type parameters must be correctly forwarded. (@see checkTypeParamOverride)
669
+ * (4) The class is not final
670
+ * (5) If the class is sealed, it is defined in the same compilation unit as the current class
669
671
*/
670
672
def checkedParentType (parent : untpd.Tree , paramAccessors : List [Symbol ]): Type = {
671
673
val ptype = parentType(parent)(ctx.superCallContext)
@@ -684,7 +686,14 @@ class Namer { typer: Typer =>
684
686
}
685
687
else if (! paramAccessors.forall(checkTypeParamOverride(pt, _)))
686
688
defn.ObjectType
687
- else pt
689
+ else {
690
+ val pclazz = pt.typeSymbol
691
+ if (pclazz.is(Final ))
692
+ ctx.error(em " cannot extend final $pclazz" , cls.pos)
693
+ if (pclazz.is(Sealed ) && pclazz.associatedFile != cls.associatedFile)
694
+ ctx.error(em " cannot extend sealed $pclazz in different compilation unit " , cls.pos)
695
+ pt
696
+ }
688
697
}
689
698
}
690
699
Original file line number Diff line number Diff line change @@ -72,8 +72,7 @@ object RefChecks {
72
72
}
73
73
}
74
74
75
- /** Check that final and sealed restrictions on class parents
76
- * and that self type of this class conforms to self types of parents.
75
+ /** Check that self type of this class conforms to self types of parents.
77
76
* and required classes.
78
77
*/
79
78
private def checkParents (cls : Symbol )(implicit ctx : Context ): Unit = cls.info match {
@@ -83,14 +82,8 @@ object RefChecks {
83
82
if (otherSelf.exists && ! (cinfo.selfType <:< otherSelf))
84
83
ctx.error(ex " $category: self type ${cinfo.selfType} of $cls does not conform to self type $otherSelf of $relation ${other.classSymbol}" , cls.pos)
85
84
}
86
- for (parent <- cinfo.classParents) {
87
- val pclazz = parent.classSymbol
88
- if (pclazz.is(Final ))
89
- ctx.error(em " cannot extend final $pclazz" , cls.pos)
90
- if (pclazz.is(Sealed ) && pclazz.associatedFile != cls.associatedFile)
91
- ctx.error(em " cannot extend sealed $pclazz in different compilation unit " , cls.pos)
85
+ for (parent <- cinfo.classParents)
92
86
checkSelfConforms(parent, " illegal inheritance" , " parent" )
93
- }
94
87
for (reqd <- cinfo.givenSelfType.classSymbols)
95
88
checkSelfConforms(reqd.typeRef, " missing requirement" , " required" )
96
89
case _ =>
Original file line number Diff line number Diff line change
1
+ trait Foo {
2
+ def foo () = new Unit with Foo // error
3
+ }
You can’t perform that action at this time.
0 commit comments