diff options
Diffstat (limited to 'test/files/run/constant-optimization.scala')
-rw-r--r-- | test/files/run/constant-optimization.scala | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/files/run/constant-optimization.scala b/test/files/run/constant-optimization.scala new file mode 100644 index 0000000000..5d13272f3b --- /dev/null +++ b/test/files/run/constant-optimization.scala @@ -0,0 +1,61 @@ +object Test extends App { + def testBothReachable() { + val i = util.Random.nextInt + val x = if (i % 2 == 0) null else "good" + val y = if (x == null) "good" else x + "" + println(s"testBothReachable: $y") + } + + def testOneReachable() { + val i = 1 + val x = if (i != 1) null else "good" + val y = if (x == null) "good" else x + "" + println(s"testOneReachable: $y") + } + + def testAllReachable() { + val i = util.Random.nextInt + val y = (i % 2) match { + case 0 => "good" + case 1 => "good" + case _ => "good" + } + println(s"testAllReachable: $y") + } + + def testOneUnreachable() { + val i = util.Random.nextInt + val x = if (i % 2 == 0) { + 1 + } else { + 2 + } + val y = x match { + case 0 => "good" + case 1 => "good" + case _ => "good" + } + println(s"testOneUnreachable: $y") + } + + def testDefaultUnreachable() { + val i = util.Random.nextInt + val x = if (i % 2 == 0) { + 1 + } else { + 2 + } + val y = x match { + case 1 => "good" + case 2 => "good" + case _ => "good" + } + println(s"testDefaultUnreachable: $y") + } + + testBothReachable() + testOneReachable() + testAllReachable() + testOneUnreachable() + testDefaultUnreachable() +} |