File tree 1 file changed +5
-3
lines changed
compiler/src/dotty/tools/dotc/typer 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -604,8 +604,9 @@ trait Checking {
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
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
607
+ * An exception is made if `cls` extends `Any`, and `parent` is `java.io.Serializable`
608
+ * or `java.lang.Comparable`. These two classes are treated by Scala as universal
609
+ * traits. E.g. the following is OK:
609
610
*
610
611
* ... extends Any with java.io.Serializable
611
612
*
@@ -617,7 +618,8 @@ trait Checking {
617
618
val psuper = parent.superClass
618
619
val csuper = cls.superClass
619
620
val ok = csuper.derivesFrom(psuper) ||
620
- parent.is(JavaDefined ) && csuper == defn.AnyClass && psuper == defn.ObjectClass
621
+ parent.is(JavaDefined ) && csuper == defn.AnyClass &&
622
+ (parent == defn.JavaSerializableClass || parent == defn.ComparableClass )
621
623
if (! ok)
622
624
ctx.error(em " illegal trait inheritance: super $csuper does not derive from $parent's super $psuper" , pos)
623
625
case _ =>
You can’t perform that action at this time.
0 commit comments