diff options
Diffstat (limited to 'compiler/src/dotty')
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/Checking.scala | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 74f1311bf..27b0f28ca 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -604,8 +604,9 @@ trait Checking { /** Given a parent `parent` of a class `cls`, if `parent` is a trait check that * the superclass of `cls` derived from the superclass of `parent`. * - * An exception is made if `cls` extends `Any`, and `parent` is a Java class - * that extends `Object`. For instance, we accept code like + * An exception is made if `cls` extends `Any`, and `parent` is `java.io.Serializable` + * or `java.lang.Comparable`. These two classes are treated by Scala as universal + * traits. E.g. the following is OK: * * ... extends Any with java.io.Serializable * @@ -617,7 +618,8 @@ trait Checking { val psuper = parent.superClass val csuper = cls.superClass val ok = csuper.derivesFrom(psuper) || - parent.is(JavaDefined) && csuper == defn.AnyClass && psuper == defn.ObjectClass + parent.is(JavaDefined) && csuper == defn.AnyClass && + (parent == defn.JavaSerializableClass || parent == defn.ComparableClass) if (!ok) ctx.error(em"illegal trait inheritance: super$csuper does not derive from $parent's super$psuper", pos) case _ => |