File tree 5 files changed +24
-12
lines changed
src/dotty/tools/dotc/typer 5 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -656,6 +656,8 @@ class Namer { typer: Typer =>
656
656
* (1) It must be a class type with a stable prefix (@see checkClassTypeWithStablePrefix)
657
657
* (2) If may not derive from itself
658
658
* (3) Overriding type parameters must be correctly forwarded. (@see checkTypeParamOverride)
659
+ * (4) The class is not final
660
+ * (5) If the class is sealed, it is defined in the same compilation unit as the current class
659
661
*/
660
662
def checkedParentType (parent : untpd.Tree , paramAccessors : List [Symbol ]): Type = {
661
663
val ptype = parentType(parent)(ctx.superCallContext)
@@ -674,7 +676,14 @@ class Namer { typer: Typer =>
674
676
}
675
677
else if (! paramAccessors.forall(checkTypeParamOverride(pt, _)))
676
678
defn.ObjectType
677
- else pt
679
+ else {
680
+ val pclazz = pt.typeSymbol
681
+ if (pclazz.is(Final ))
682
+ ctx.error(em " cannot extend final $pclazz" , cls.pos)
683
+ if (pclazz.is(Sealed ) && pclazz.associatedFile != cls.associatedFile)
684
+ ctx.error(em " cannot extend sealed $pclazz in different compilation unit " , cls.pos)
685
+ pt
686
+ }
678
687
}
679
688
}
680
689
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
+ }
Original file line number Diff line number Diff line change @@ -15,8 +15,6 @@ object Test {
15
15
class C (val a : Int ) extends AnyVal // error: value class may not be a local class
16
16
new C (1 )
17
17
}
18
- class B1 (val b : Int ) extends B (b) // error: cannot extend final class B
19
- // class D extends B( { class E(val a: Int) extends AnyVal; new E(1) } )
20
18
}
21
19
22
20
Original file line number Diff line number Diff line change
1
+ class Foo {
2
+ class B (val a : Int ) extends AnyVal
3
+ }
4
+
5
+ object Test {
6
+ class B1 (val b : Int ) extends B (b) // error: cannot extend final class B
7
+ }
8
+
9
+
You can’t perform that action at this time.
0 commit comments