summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-10-14 17:34:54 +0000
committerPaul Phillips <paulp@improving.org>2010-10-14 17:34:54 +0000
commit185700607dc2fd12cf47a61f583bdbafd726558b (patch)
treede5ce98a84176042276101368c07cd828625b334 /test
parent920449d6eeb0267f96b115a47866ccd53a5a3c55 (diff)
downloadscala-185700607dc2fd12cf47a61f583bdbafd726558b.tar.gz
scala-185700607dc2fd12cf47a61f583bdbafd726558b.tar.bz2
scala-185700607dc2fd12cf47a61f583bdbafd726558b.zip
Modification to the widening logic to treat loc...
Modification to the widening logic to treat locally defined symbols like final members thus allowing more constants to be inlined. Concretely, that means that in code like this: def f: Unit = { val b = false ; if (b) println("ok") } The call to println is no longer generated at all, and in this code: def f(x: Int) = { val X = 1 ; val Y = 2; x match { case X => 1 ; case Y => 2 } } A tableswitch is generated instead of the present if/then/else. I also added a big comment to the former widenIfNotFinal (now widenIfNecessary for obvious reasons.) Review by rytz.
Diffstat (limited to 'test')
-rw-r--r--test/files/pos/no-widen-locals.scala17
-rw-r--r--test/files/run/constrained-types.check4
-rw-r--r--test/files/run/constrained-types.scala2
3 files changed, 20 insertions, 3 deletions
diff --git a/test/files/pos/no-widen-locals.scala b/test/files/pos/no-widen-locals.scala
new file mode 100644
index 0000000000..32579404b2
--- /dev/null
+++ b/test/files/pos/no-widen-locals.scala
@@ -0,0 +1,17 @@
+import annotation.switch
+
+object Test {
+ def f(x: Int) = {
+ val X1 = 5
+ val X2 = 10
+ val X3 = 15
+ val X4 = 20
+
+ (x: @switch) match {
+ case X1 => 1
+ case X2 => 2
+ case X3 => 3
+ case X4 => 4
+ }
+ }
+}
diff --git a/test/files/run/constrained-types.check b/test/files/run/constrained-types.check
index 8050017659..dbad841d99 100644
--- a/test/files/run/constrained-types.check
+++ b/test/files/run/constrained-types.check
@@ -92,8 +92,8 @@ def m = {
val x = "three"
val y : String @Annot(x) = x
y
-} // x should be existentially bound
-m: java.lang.String @Annot(x) forSome { val x: java.lang.String }
+} // x should not escape the local scope with a narrow type
+m: String @Annot("three")
-----
def n(y: String) = {
diff --git a/test/files/run/constrained-types.scala b/test/files/run/constrained-types.scala
index c03c144ad1..62abfe9e31 100644
--- a/test/files/run/constrained-types.scala
+++ b/test/files/run/constrained-types.scala
@@ -61,7 +61,7 @@ object Test {
| val x = "three"
| val y : String @Annot(x) = x
| y
- |} // x should be existentially bound""",
+ |} // x should not escape the local scope with a narrow type""",
"""def n(y: String) = {
| def m(x: String) : String @Annot(x) = {