diff options
author | Dmitry Petrashko <dark@d-d.me> | 2017-04-19 06:58:40 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-19 06:58:40 -0500 |
commit | 02e38832668ed2a0504a77dd4f86270fa1a1d4bf (patch) | |
tree | 5f931022c36fc3cf8ef585e4bcc08f554f92142e /compiler/src/dotty/tools/dotc/core | |
parent | 4623e1282ebe7dfc31cb12411fed16457ed289ca (diff) | |
parent | 983ce8da3ce321bed7f8100c00b4aa709528208e (diff) | |
download | dotty-02e38832668ed2a0504a77dd4f86270fa1a1d4bf.tar.gz dotty-02e38832668ed2a0504a77dd4f86270fa1a1d4bf.tar.bz2 dotty-02e38832668ed2a0504a77dd4f86270fa1a1d4bf.zip |
Merge pull request #2267 from dotty-staging/fix-constant-lazy-vals
Fix #2266: Do not replace constant type lazy vals with constant.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/core')
-rw-r--r-- | compiler/src/dotty/tools/dotc/core/Constants.scala | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Constants.scala b/compiler/src/dotty/tools/dotc/core/Constants.scala index ed388b7ec..8ea285c8d 100644 --- a/compiler/src/dotty/tools/dotc/core/Constants.scala +++ b/compiler/src/dotty/tools/dotc/core/Constants.scala @@ -53,6 +53,20 @@ object Constants { def isNonUnitAnyVal = BooleanTag <= tag && tag <= DoubleTag def isAnyVal = UnitTag <= tag && tag <= DoubleTag + /** Is the zero or un-initialized value of the type */ + def isZero(implicit ctx: Context): Boolean = tag match { + case BooleanTag => !value.asInstanceOf[Boolean] + case ByteTag => value.asInstanceOf[Byte] == 0 + case ShortTag => value.asInstanceOf[Short] == 0 + case CharTag => value.asInstanceOf[Char] == 0 + case IntTag => value.asInstanceOf[Int] == 0 + case LongTag => value.asInstanceOf[Long] == 0L + case FloatTag => value.asInstanceOf[Float] == 0.0 + case DoubleTag => value.asInstanceOf[Double] == 0.0 + case NullTag => true + case _ => false + } + def tpe(implicit ctx: Context): Type = tag match { case UnitTag => defn.UnitType case BooleanTag => defn.BooleanType |