aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-12-10 15:37:37 +0100
committerMartin Odersky <odersky@gmail.com>2015-12-14 14:30:09 +0100
commit3476bab33e9509963fd02aab10b4db3b891c9a85 (patch)
tree44ed2633e7af264f4980b387422eeb05d3ff2504 /src
parentc4238b13b3eb89abeac49aa814313c9adc75599c (diff)
downloaddotty-3476bab33e9509963fd02aab10b4db3b891c9a85.tar.gz
dotty-3476bab33e9509963fd02aab10b4db3b891c9a85.tar.bz2
dotty-3476bab33e9509963fd02aab10b4db3b891c9a85.zip
Better diagnostics for clashing classes
We do not allow same-named class members in supertraits of a mixin composition anymore. This commit gives a better error message and avoids a crash in RefChecks.
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/core/Denotations.scala2
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala2
-rw-r--r--src/dotty/tools/dotc/core/Types.scala2
-rw-r--r--src/dotty/tools/dotc/typer/RefChecks.scala19
4 files changed, 18 insertions, 7 deletions
diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala
index b6519e1cd..fcd60ef16 100644
--- a/src/dotty/tools/dotc/core/Denotations.scala
+++ b/src/dotty/tools/dotc/core/Denotations.scala
@@ -324,7 +324,7 @@ object Denotations {
info1 // follow Scala2 linearization -
// compare with way merge is performed in SymDenotation#computeMembersNamed
else
- throw new MergeError(s"${ex.getMessage} as members of type ${pre.show}")
+ throw new MergeError(s"${ex.getMessage} as members of type ${pre.show}", ex.tp1, ex.tp2)
}
new JointRefDenotation(sym, jointInfo, denot1.validFor & denot2.validFor)
}
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index f8ff84ba1..71dede951 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -1168,7 +1168,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
case bounds: TypeBounds => i"type bounds $bounds"
case _ => tp.show
}
- throw new MergeError(s"cannot merge ${showType(tp1)} with ${showType(tp2)}")
+ throw new MergeError(s"cannot merge ${showType(tp1)} with ${showType(tp2)}", tp1, tp2)
}
/** Merge two lists of names. If names in corresponding positions match, keep them,
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 159e776b4..0691d979a 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -3318,7 +3318,7 @@ object Types {
}
}
- class MergeError(msg: String) extends TypeError(msg)
+ class MergeError(msg: String, val tp1: Type, val tp2: Type) extends TypeError(msg)
// ----- Debug ---------------------------------------------------------
diff --git a/src/dotty/tools/dotc/typer/RefChecks.scala b/src/dotty/tools/dotc/typer/RefChecks.scala
index 3ffbb8079..416a2cb92 100644
--- a/src/dotty/tools/dotc/typer/RefChecks.scala
+++ b/src/dotty/tools/dotc/typer/RefChecks.scala
@@ -15,6 +15,7 @@ import TreeTransforms._
import util.DotClass
import scala.util.{Try, Success, Failure}
import config.{ScalaVersion, NoScalaVersion}
+import Decorators._
import typer.ErrorReporting._
import DenotTransformers._
import ValueClasses.isDerivedValueClass
@@ -340,10 +341,20 @@ object RefChecks {
}*/
}
- val opc = new OverridingPairs.Cursor(clazz)
- while (opc.hasNext) {
- checkOverride(opc.overriding, opc.overridden)
- opc.next()
+ try {
+ val opc = new OverridingPairs.Cursor(clazz)
+ while (opc.hasNext) {
+ checkOverride(opc.overriding, opc.overridden)
+ opc.next()
+ }
+ } catch {
+ case ex: MergeError =>
+ val addendum = ex.tp1 match {
+ case tp1: ClassInfo =>
+ "\n(Note that having same-named member classes in types of a mixin composition is no longer allowed)"
+ case _ => ""
+ }
+ ctx.error(ex.getMessage + addendum, clazz.pos)
}
printMixinOverrideErrors()