aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Types.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-04-23 16:19:39 +0200
committerMartin Odersky <odersky@gmail.com>2013-04-23 16:19:39 +0200
commit8566b093c35d5cc5b29544b5b2c3f01b0ec4c1bd (patch)
treeae5e531eccd82bae275833f19c979ee2692b8368 /src/dotty/tools/dotc/core/Types.scala
parentae816296034133b1dee25020224b9f7a334c8928 (diff)
downloaddotty-8566b093c35d5cc5b29544b5b2c3f01b0ec4c1bd.tar.gz
dotty-8566b093c35d5cc5b29544b5b2c3f01b0ec4c1bd.tar.bz2
dotty-8566b093c35d5cc5b29544b5b2c3f01b0ec4c1bd.zip
Changed classSymbol so that it returns traits as well as classes.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r--src/dotty/tools/dotc/core/Types.scala20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 60f329bc6..e4209ba98 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -178,19 +178,15 @@ object Types {
case _ => NoSymbol
}
- /** The least non-trait class of which this type is a subtype. NoSymbol is none exists.
- * Note: can't do the same for traits as that would be ambiguous. */
+ /** The least class or trait of which this type is a subtype, or
+ * NoSymbol if none exists (either because this type is not a
+ * value type, or because superclasses are ambiguous).
+ */
final def classSymbol(implicit ctx: Context): Symbol = this match {
case tp: ClassInfo =>
- if (tp.cls is Trait)
- tp.classParents match {
- case p :: ps => p.classSymbol
- case nil => NoSymbol
- }
- else tp.cls
+ tp.cls
case tp: TypeProxy =>
- tp.underlying.typeSymbol // this should be classSymbol, but that produces
- // stackoverflows at the moment. Need to follow up on this.
+ tp.underlying.classSymbol
case AndType(l, r) =>
val lsym = l.classSymbol
val rsym = r.classSymbol
@@ -200,7 +196,9 @@ object Types {
case OrType(l, r) =>
val lsym = l.classSymbol
val rsym = r.classSymbol
- lsym.info.baseClasses.find(rsym.isSubClass).getOrElse(NoSymbol)
+ if (lsym.isSubClass(rsym)) rsym
+ else if (rsym.isSubClass(lsym)) lsym
+ else NoSymbol
case _ =>
NoSymbol
}