File tree Expand file tree Collapse file tree 4 files changed +22
-1
lines changed
test/dotty/tools/dotc/reporting Expand file tree Collapse file tree 4 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,7 @@ public enum ErrorMessageID {
100
100
NoReturnFromInlineID ,
101
101
ReturnOutsideMethodDefinitionID ,
102
102
UncheckedTypePatternID ,
103
+ ExtendFinalClassID ,
103
104
;
104
105
105
106
public int errorNumber () {
Original file line number Diff line number Diff line change @@ -1770,4 +1770,12 @@ object messages {
1770
1770
| """
1771
1771
}
1772
1772
1773
+ case class ExtendFinalClass (clazz: Symbol , finalClazz : Symbol )(implicit ctx : Context )
1774
+ extends Message (ExtendFinalClassID ) {
1775
+ val kind = " Syntax"
1776
+ val msg = hl " $clazz cannot extend ${" final" } $finalClazz"
1777
+ val explanation =
1778
+ hl """ A class marked with the ${" final" } keyword cannot be extended """
1779
+ }
1780
+
1773
1781
}
Original file line number Diff line number Diff line change @@ -876,7 +876,7 @@ class Namer { typer: Typer =>
876
876
else {
877
877
val pclazz = pt.typeSymbol
878
878
if (pclazz.is(Final ))
879
- ctx.error(em " cannot extend final $ pclazz" , cls.pos)
879
+ ctx.error(ExtendFinalClass (cls, pclazz) , cls.pos)
880
880
if (pclazz.is(Sealed ) && pclazz.associatedFile != cls.associatedFile)
881
881
ctx.error(em " cannot extend sealed $pclazz in different compilation unit " , cls.pos)
882
882
pt
Original file line number Diff line number Diff line change @@ -998,4 +998,16 @@ class ErrorMessagesTests extends ErrorMessagesTest {
998
998
val ReturnOutsideMethodDefinition (owner) :: Nil = messages
999
999
assertEquals(" object A" , owner.show)
1000
1000
}
1001
+ @ Test def extendFinalClass = checkMessagesAfter(" refchecks" ) {
1002
+ """ final class A
1003
+ |
1004
+ |class B extends A
1005
+ """ .stripMargin
1006
+ }.expect { (ictx, messages) =>
1007
+ implicit val ctx : Context = ictx
1008
+ assertMessageCount(1 , messages)
1009
+ val ExtendFinalClass (extender, parent) :: Nil = messages
1010
+ assertEquals(extender.show, " class B" )
1011
+ assertEquals(parent.show, " class A" )
1012
+ }
1001
1013
}
You can’t perform that action at this time.
0 commit comments