diff options
author | Nicolas Stucki <nicolas.stucki@gmail.com> | 2017-04-16 18:48:53 +0200 |
---|---|---|
committer | Nicolas Stucki <nicolas.stucki@gmail.com> | 2017-04-16 18:48:53 +0200 |
commit | 2324be56376aed8cd168e712001485f2202cdda6 (patch) | |
tree | 46ccb7fdd77e94f235a5defb93b13f0c38c37015 /compiler/src/dotty/tools/dotc/core/Constants.scala | |
parent | a370eed7bebbc534e19de7dadefd72a70349854f (diff) | |
download | dotty-2324be56376aed8cd168e712001485f2202cdda6.tar.gz dotty-2324be56376aed8cd168e712001485f2202cdda6.tar.bz2 dotty-2324be56376aed8cd168e712001485f2202cdda6.zip |
Fix constant type val value inline in constructors.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/core/Constants.scala')
-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 |