@@ -638,7 +638,7 @@ trait Checking {
638
638
*
639
639
* The standard library relies on this idiom.
640
640
*/
641
- def checkTraitInheritance (parent : Symbol , cls : ClassSymbol , pos : Position )(implicit ctx : Context ): Unit = {
641
+ def checkTraitInheritance (parent : Symbol , cls : ClassSymbol , pos : Position )(implicit ctx : Context ): Unit =
642
642
parent match {
643
643
case parent : ClassSymbol if parent is Trait =>
644
644
val psuper = parent.superClass
@@ -650,7 +650,18 @@ trait Checking {
650
650
ctx.error(em " illegal trait inheritance: super $csuper does not derive from $parent's super $psuper" , pos)
651
651
case _ =>
652
652
}
653
- }
653
+
654
+ /** Check that case classes are not inherited by case classes.
655
+ */
656
+ def checkCaseInheritance (parent : Symbol , caseCls : ClassSymbol , pos : Position )(implicit ctx : Context ): Unit =
657
+ parent match {
658
+ case parent : ClassSymbol =>
659
+ if (parent is Case )
660
+ ctx.error(ex """ case $caseCls has case ancestor $parent, but case-to-case inheritance is prohibited.
661
+ |To overcome this limitation, use extractors to pattern match on non-leaf nodes. """ , pos)
662
+ else checkCaseInheritance(parent.superClass, caseCls, pos)
663
+ case _ =>
664
+ }
654
665
655
666
/** Check that method parameter types do not reference their own parameter
656
667
* or later parameters in the same parameter section.
@@ -686,5 +697,6 @@ trait NoChecking extends Checking {
686
697
override def checkNotSingleton (tpt : Tree , where : String )(implicit ctx : Context ): Tree = tpt
687
698
override def checkDerivedValueClass (clazz : Symbol , stats : List [Tree ])(implicit ctx : Context ) = ()
688
699
override def checkTraitInheritance (parentSym : Symbol , cls : ClassSymbol , pos : Position )(implicit ctx : Context ) = ()
700
+ override def checkCaseInheritance (parentSym : Symbol , caseCls : ClassSymbol , pos : Position )(implicit ctx : Context ) = ()
689
701
override def checkNoForwardDependencies (vparams : List [ValDef ])(implicit ctx : Context ): Unit = ()
690
702
}
0 commit comments