diff options
author | Lex Spoon <lex@lexspoon.org> | 2006-02-21 16:47:45 +0000 |
---|---|---|
committer | Lex Spoon <lex@lexspoon.org> | 2006-02-21 16:47:45 +0000 |
commit | 710c9301a3a5573fd6ff92acf882a794af28df95 (patch) | |
tree | dd58c0d016ac6ec56b1b42929a24c262c6d576ba /src/compiler | |
parent | 15fea20ac4d2daaf81ee8320888b42231526270c (diff) | |
download | scala-710c9301a3a5573fd6ff92acf882a794af28df95.tar.gz scala-710c9301a3a5573fd6ff92acf882a794af28df95.tar.bz2 scala-710c9301a3a5573fd6ff92acf882a794af28df95.zip |
avoid crashing the compiler if folding constants
raises an arithmetic exception
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala b/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala index 0afb18d8d5..19a4484e1f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala @@ -24,9 +24,16 @@ abstract class ConstantFolder { case _ => null }); - private def fold(tree: Tree, x: Constant): Tree = - if (x != null && x.tag != UnitTag) tree setType ConstantType(x) - else 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; + } catch { + case _:ArithmeticException => tree // the code will crash at runtime, + // but that is better than the + // compiler itself crashing + } private def foldUnop(op: Name, x: Constant): Constant = Pair(op, x.tag) match { case Pair(nme.ZNOT, BooleanTag) => Constant(!x.booleanValue) |