diff options
author | Martin Odersky <odersky@gmail.com> | 2015-12-13 15:34:38 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-12-13 15:34:38 +0100 |
commit | 95098ba498b5317002395008376a565550189673 (patch) | |
tree | aca69a2106a2633df6ca26c10caa840276603d0a /src | |
parent | b59395843b872d5c95052aa1e2f81c2c2fc172f1 (diff) | |
download | dotty-95098ba498b5317002395008376a565550189673.tar.gz dotty-95098ba498b5317002395008376a565550189673.tar.bz2 dotty-95098ba498b5317002395008376a565550189673.zip |
Shortcut in derivesFrom for high bound Any.
Any is a supertype of every other type, so no need to analyze types in detail.
This also fixes the cyclic reference error observed for sets.scala, but only
for the special case where the base class is Any.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index f65633595..596d1ba24 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -141,20 +141,23 @@ object Types { } /** Is this type an instance of a non-bottom subclass of the given class `cls`? */ - final def derivesFrom(cls: Symbol)(implicit ctx: Context): Boolean = this match { - case tp: TypeRef => - val sym = tp.symbol - if (sym.isClass) sym.derivesFrom(cls) else tp.underlying.derivesFrom(cls) - case tp: TypeProxy => - tp.underlying.derivesFrom(cls) - case tp: AndType => - tp.tp1.derivesFrom(cls) || tp.tp2.derivesFrom(cls) - case tp: OrType => - tp.tp1.derivesFrom(cls) && tp.tp2.derivesFrom(cls) - case tp: JavaArrayType => - cls == defn.ObjectClass - case _ => - false + final def derivesFrom(cls: Symbol)(implicit ctx: Context): Boolean = { + def loop(tp: Type) = tp match { + case tp: TypeRef => + val sym = tp.symbol + if (sym.isClass) sym.derivesFrom(cls) else tp.underlying.derivesFrom(cls) + case tp: TypeProxy => + tp.underlying.derivesFrom(cls) + case tp: AndType => + tp.tp1.derivesFrom(cls) || tp.tp2.derivesFrom(cls) + case tp: OrType => + tp.tp1.derivesFrom(cls) && tp.tp2.derivesFrom(cls) + case tp: JavaArrayType => + cls == defn.ObjectClass + case _ => + false + } + cls == defn.AnyClass || loop(this) } /** Is this type guaranteed not to have `null` as a value? |