File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -603,12 +603,25 @@ trait Checking {
603
603
604
604
/** Given a parent `parent` of a class `cls`, if `parent` is a trait check that
605
605
* the superclass of `cls` derived from the superclass of `parent`.
606
+ *
607
+ * An exception is made if `cls` extends `Any`, and `parent` is a Java class
608
+ * that extends `Object`. For instance, we accept code like
609
+ *
610
+ * ... extends Any with java.io.Serializable
611
+ *
612
+ * The standard library relies on this idiom.
606
613
*/
607
- def checkTraitInheritance (parent : Symbol , cls : ClassSymbol , pos : Position )(implicit ctx : Context ): Unit =
614
+ def checkTraitInheritance (parent : Symbol , cls : ClassSymbol , pos : Position )(implicit ctx : Context ): Unit = {
608
615
parent match {
609
- case parent : ClassSymbol if parent.is(Trait ) && ! cls.superClass.derivesFrom(parent.superClass) =>
610
- ctx.error(em " illegal trait inheritance: super ${cls.superClass} does not derive from $parent's super ${parent.superClass}" , pos)
616
+ case parent : ClassSymbol if parent is Trait =>
617
+ val psuper = parent.superClass
618
+ val csuper = cls.superClass
619
+ val ok = csuper.derivesFrom(psuper) ||
620
+ parent.is(JavaDefined ) && csuper == defn.AnyClass && psuper == defn.ObjectClass
621
+ if (! ok)
622
+ ctx.error(em " illegal trait inheritance: super $csuper does not derive from $parent's super $psuper" , pos)
611
623
case _ =>
624
+ }
612
625
}
613
626
}
614
627
You can’t perform that action at this time.
0 commit comments