diff options
author | Martin Odersky <odersky@gmail.com> | 2013-04-05 16:38:35 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-04-05 16:38:35 +0200 |
commit | 459a734cb51e204d114c0b7c695ad71d618bc696 (patch) | |
tree | 71bb2ad10be30cae22799a0d9677be79b177ef1d /src | |
parent | bb7507f31b892662cb502550ca38bc93011697a9 (diff) | |
download | dotty-459a734cb51e204d114c0b7c695ad71d618bc696.tar.gz dotty-459a734cb51e204d114c0b7c695ad71d618bc696.tar.bz2 dotty-459a734cb51e204d114c0b7c695ad71d618bc696.zip |
Added new classSymbol method for Types.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 3363f9af1..d296acea1 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -161,6 +161,31 @@ object Types { case _ => NoSymbol } + /** The least non-trait class of which this type is a subtype. NoSymbol is none exists. */ + 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 + case tp: TypeProxy => + tp.underlying.typeSymbol + case AndType(l, r) => + val lsym = l.classSymbol + val rsym = r.classSymbol + if (lsym.isSubClass(rsym)) lsym + else if (rsym.isSubClass(lsym)) rsym + else NoSymbol + case OrType(l, r) => + val lsym = l.classSymbol + val rsym = r.classSymbol + lsym.info.baseClasses.find(rsym.isSubClass).getOrElse(NoSymbol) + case _ => + NoSymbol + } + /** The term symbol associated with the type */ final def termSymbol(implicit ctx: Context): Symbol = this match { case tp: TermRef => tp.symbol @@ -669,7 +694,7 @@ object Types { */ final def splitArray(implicit ctx: Context): (Int, Type) = { def recur(n: Int, tp: Type): (Int, Type) = tp match { - case RefinedType(tycon, _) if tycon.typeSymbol == defn.ArrayType => + case RefinedType(tycon, _) if tycon.dealias.typeSymbol == defn.ArrayClass => tp.typeArgs match { case arg :: Nil => recur(n + 1, arg) case _ => (n, tp) |