aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/typer/Checking.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-02-03 10:11:42 +1100
committerMartin Odersky <odersky@gmail.com>2017-02-08 22:20:26 +1100
commit54cd06526acf1cc45cbf3480ece4885f8853ab18 (patch)
treedb8d4f927cf76ae73ff29e958fd015150fc99e93 /compiler/src/dotty/tools/dotc/typer/Checking.scala
parent0828a5275ace05ac3bcc89c3fbbced389fab7107 (diff)
downloaddotty-54cd06526acf1cc45cbf3480ece4885f8853ab18.tar.gz
dotty-54cd06526acf1cc45cbf3480ece4885f8853ab18.tar.bz2
dotty-54cd06526acf1cc45cbf3480ece4885f8853ab18.zip
Narrow Java exception to inheritance rule
Excepted are only Serializable and Comparable. This follows scalac's behavior.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/typer/Checking.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Checking.scala8
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 _ =>