diff options
author | Martin Odersky <odersky@gmail.com> | 2014-02-03 22:34:15 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-02-03 22:34:15 +0100 |
commit | 79c4490a823f779251f4f2b4a332e639e6ad00d6 (patch) | |
tree | 5a67001710421e73b0c64c5737b0a3a76d0225cd /src/dotty/tools/dotc/core/Constants.scala | |
parent | 16829831dcf417d7af409ecdd965b59b886921cd (diff) | |
download | dotty-79c4490a823f779251f4f2b4a332e639e6ad00d6.tar.gz dotty-79c4490a823f779251f4f2b4a332e639e6ad00d6.tar.bz2 dotty-79c4490a823f779251f4f2b4a332e639e6ad00d6.zip |
More robust constant folding
Can now also convert a constant to a type that's lower-bounded by a primitive numeric type.
Diffstat (limited to 'src/dotty/tools/dotc/core/Constants.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Constants.scala | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/core/Constants.scala b/src/dotty/tools/dotc/core/Constants.scala index 50bebefe9..b04ec0e89 100644 --- a/src/dotty/tools/dotc/core/Constants.scala +++ b/src/dotty/tools/dotc/core/Constants.scala @@ -167,10 +167,15 @@ object Constants { /** Convert constant value to conform to given type. */ def convertTo(pt: Type)(implicit ctx: Context): Constant = { - val target = pt.typeSymbol + def lowerBound(pt: Type): Type = pt.dealias.stripTypeVar match { + case tref: TypeRef if !tref.symbol.isClass => lowerBound(tref.info.bounds.lo) + case param: PolyParam => lowerBound(ctx.typeComparer.bounds(param).lo) + case pt => pt + } + val target = lowerBound(pt).typeSymbol if (target == tpe.typeSymbol) this - else if (target == defn.ByteClass && isByteRange) + else if ((target == defn.ByteClass) && isByteRange) Constant(byteValue) else if (target == defn.ShortClass && isShortRange) Constant(shortValue) |