diff options
author | Martin Odersky <odersky@gmail.com> | 2006-08-14 16:40:46 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2006-08-14 16:40:46 +0000 |
commit | eb79135b976114e75526a0d5b37401f110d47136 (patch) | |
tree | f5ff36ebc13de39c66ea909b0bc59accb50819a4 /src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala | |
parent | c840d9f58c3d3dd9dbb5581df86985d6600fa09a (diff) | |
download | scala-eb79135b976114e75526a0d5b37401f110d47136.tar.gz scala-eb79135b976114e75526a0d5b37401f110d47136.tar.bz2 scala-eb79135b976114e75526a0d5b37401f110d47136.zip |
Fixed bug 697
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala b/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala index 32d7fcd800..a19c5799d4 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala @@ -16,21 +16,21 @@ abstract class ConstantFolder { case Apply(Select(Literal(x), op), List(Literal(y))) => foldBinop(op, x, y) case Select(Literal(x), op) => foldUnop(op, x) case _ => null - }); + }) /** If tree is a constant value that can be converted to type `pt', perform the conversion */ def apply(tree: Tree, pt: Type): Tree = fold(tree, tree.tpe match { case ConstantType(x) => x convertTo pt case _ => null - }); + }) - private def fold(tree: Tree, compX: =>Constant): Tree = + private def fold(tree: Tree, compX: => Constant): Tree = try { val x = compX if (x != null && x.tag != UnitTag) tree setType ConstantType(x) - else tree; + else tree } catch { - case _:ArithmeticException => tree // the code will crash at runtime, + case _: ArithmeticException => tree // the code will crash at runtime, // but that is better than the // compiler itself crashing } @@ -55,7 +55,10 @@ abstract class ConstantFolder { } private def foldBinop(op: Name, x: Constant, y: Constant): Constant = try { - val optag = if (x.tag > y.tag) x.tag else y.tag; + val optag = if (x.tag == y.tag) x.tag + else if (isNumeric(x.tag) && isNumeric(y.tag)) + if (x.tag > y.tag) x.tag else y.tag + else NoTag optag match { case BooleanTag => op match { |