diff options
author | Martin Odersky <odersky@gmail.com> | 2016-01-29 23:46:00 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-02-09 09:40:52 +0100 |
commit | 41f056750990a2e6391eec3436077715041d2b8a (patch) | |
tree | ede383d5ec756b7a391e747eac472a1dc8f77755 /src/dotty/tools/dotc/core/Types.scala | |
parent | 633e2ebfd42af65f8324aec87a2444bb9cec5eff (diff) | |
download | dotty-41f056750990a2e6391eec3436077715041d2b8a.tar.gz dotty-41f056750990a2e6391eec3436077715041d2b8a.tar.bz2 dotty-41f056750990a2e6391eec3436077715041d2b8a.zip |
Use isRealizable to identify stable prefixes
Replaces isVolatile, which is too weak (and more complicated).
Backwards compatibility with Scala2 is ensured by dropping the
requirement in Scala2 mode.
Fixes #1047, which now compiles without inifinite recursion.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 47a4f088f..1d4e80601 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -127,6 +127,23 @@ object Types { false } + /** Is this type realizable in all contexts? */ + def isRealizable(implicit ctx: Context): Boolean = dealias match { + case tp: TermRef => tp.symbol.isStable + case tp: SingletonType => true + case tp => + def isConcrete(tp: Type): Boolean = tp.dealias match { + case tp: TypeRef => tp.symbol.isClass + case tp: TypeProxy => isConcrete(tp.underlying) + case tp: AndOrType => isConcrete(tp.tp1) && isConcrete(tp.tp2) + case _ => false + } + isConcrete(tp) && tp.abstractTypeMembers.forall { m => + val bounds = m.info.bounds + bounds.lo <:< bounds.hi + } + } + /** Does this type refer exactly to class symbol `sym`, instead of to a subclass of `sym`? * Implemented like `isRef`, but follows more types: all type proxies as well as and- and or-types */ |