File tree 4 files changed +15
-4
lines changed
compiler/src/dotty/tools/dotc 4 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -2138,7 +2138,7 @@ object messages {
2138
2138
2139
2139
case class ClassCannotExtendEnum (cls : Symbol , parent : Symbol )(implicit ctx : Context ) extends Message (ClassCannotExtendEnumID ) {
2140
2140
override def kind : String = " Syntax"
2141
- override def msg : String = hl """ Normal case class cannot extend an enum. case $cls in ${cls.owner} is extending enum ${parent.name}. """
2141
+ override def msg : String = hl """ $cls in ${cls.owner} extends enum ${parent.name}, but extending enums is prohibited ."""
2142
2142
override def explanation : String = " "
2143
2143
}
2144
2144
Original file line number Diff line number Diff line change @@ -908,7 +908,12 @@ trait Checking {
908
908
cls.owner.isTerm &&
909
909
(cls.owner.flagsUNSAFE.is(Case ) || cls.owner.name == nme.DOLLAR_NEW )
910
910
if (! cdef.mods.isEnumCase && ! isEnumAnonCls) {
911
- if (cls.is(Case ))
911
+ // Since enums are classes and Namer checks that classes don't extend multiple classes, we only check the class
912
+ // parent.
913
+ //
914
+ // Unlike firstParent.derivesFrom(defn.EnumClass), this test allows inheriting from `Enum` by hand;
915
+ // see enum-List-control.scala.
916
+ if (cls.is(Case ) || firstParent.is(Enum ))
912
917
ctx.error(ClassCannotExtendEnum (cls, firstParent), cdef.pos)
913
918
}
914
919
}
Original file line number Diff line number Diff line change
1
+ enum Foo { case A }
2
+ enum Bar { case A }
3
+ enum Baz extends Foo { case Z } // error
4
+
5
+ enum Quux extends Foo with Bar { case Z } // error
6
+
7
+ class Quuw extends Foo // error
8
+ class Quuz extends Foo { val enumTag = 1 } // error
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments