@@ -846,14 +846,21 @@ trait Checking {
846846 }
847847
848848 /** Check that all case classes that extend `scala.Enum` are `enum` cases */
849- def checkEnum (cdef : untpd.TypeDef , cls : Symbol )(implicit ctx : Context ): Unit = {
849+ def checkEnum (cdef : untpd.TypeDef , cls : Symbol , firstParent : Symbol )(implicit ctx : Context ): Unit = {
850850 import untpd .modsDeco
851851 def isEnumAnonCls =
852852 cls.isAnonymousClass &&
853853 cls.owner.isTerm &&
854854 (cls.owner.flagsUNSAFE.is(Case ) || cls.owner.name == nme.DOLLAR_NEW )
855- if (! cdef.mods.isEnumCase && ! isEnumAnonCls)
856- ctx.error(em " normal case $cls in ${cls.owner} cannot extend an enum " , cdef.pos)
855+ if (! cdef.mods.isEnumCase && ! isEnumAnonCls) {
856+ if (cls.is(Case ))
857+ ctx.error(em " normal case $cls in ${cls.owner} cannot extend an enum " , cdef.pos)
858+ else if (firstParent != defn.EnumClass && firstParent.derivesFrom(defn.EnumClass ) && ! cdef.mods.isEnumCase && ! isEnumAnonCls)
859+ // Since enums are classes and Namer checks that classes don't extend multiple classes, we only check the class
860+ // parent.
861+ // Tricky to phrase; language taken from "case-to-case inheritance is prohibited".
862+ ctx.error(s " ${cls.name} has enum ancestor ${firstParent.name}, but inheriting from enums is prohibited " , cdef.pos)
863+ }
857864 }
858865
859866 /** Check that all references coming from enum cases in an enum companion object
@@ -931,7 +938,7 @@ trait Checking {
931938
932939trait ReChecking extends Checking {
933940 import tpd ._
934- override def checkEnum (cdef : untpd.TypeDef , cls : Symbol )(implicit ctx : Context ): Unit = ()
941+ override def checkEnum (cdef : untpd.TypeDef , cls : Symbol , firstParent : Symbol )(implicit ctx : Context ): Unit = ()
935942 override def checkRefsLegal (tree : tpd.Tree , badOwner : Symbol , allowed : (Name , Symbol ) => Boolean , where : String )(implicit ctx : Context ): Unit = ()
936943 override def checkEnumCompanions (stats : List [Tree ], enumContexts : collection.Map [Symbol , Context ])(implicit ctx : Context ): List [Tree ] = stats
937944}
0 commit comments