summaryrefslogtreecommitdiff
path: root/test/files/neg/sealed-final-neg.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-07-25 15:21:16 -0700
committerPaul Phillips <paulp@improving.org>2012-07-26 10:04:20 -0700
commitadeffda25e94ed0206d35bdb9b42523227a89f8c (patch)
tree1c07a172eadb99b5854ccee6c288097df4e24fe0 /test/files/neg/sealed-final-neg.scala
parentfe513d1f147e60988414b01e5928811bb6f78714 (diff)
downloadscala-adeffda25e94ed0206d35bdb9b42523227a89f8c.tar.gz
scala-adeffda25e94ed0206d35bdb9b42523227a89f8c.tar.bz2
scala-adeffda25e94ed0206d35bdb9b42523227a89f8c.zip
Refined isEffectivelyFinal logic for sealedness.
If the enclosing class of a method is sealed and has only final subclasses, then the method is effectively final in the sealed class if none of the subclasses overrides it. This makes it possible to inline more methods without explicitly marking them final. Note that the test doesn't fail before this patch due to SI-6142, a bug in the optimizer, but here's a bytecode diff to prove it: @@ -16,8 +16,10 @@ public final class Test$ { Code: : getstatic // Field Foo$.MODULE$:LFoo$; : invokevirtual // Method Foo$.mkFoo:()LFoo; +: pop : bipush -: invokevirtual // Method Foo.bar:(I)I +: iconst_1 +: iadd : ireturn And the test in neg, which is manually made to fail due to the absence of inline warnings, correctly refuses to inline the methods. Review by @dragos.
Diffstat (limited to 'test/files/neg/sealed-final-neg.scala')
-rw-r--r--test/files/neg/sealed-final-neg.scala41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/files/neg/sealed-final-neg.scala b/test/files/neg/sealed-final-neg.scala
new file mode 100644
index 0000000000..bc25330e13
--- /dev/null
+++ b/test/files/neg/sealed-final-neg.scala
@@ -0,0 +1,41 @@
+package neg1 {
+ sealed abstract class Foo {
+ @inline def bar(x: Int) = x + 1
+ }
+ object Foo {
+ def mkFoo(): Foo = new Baz2
+ }
+
+ object Baz1 extends Foo
+ final class Baz2 extends Foo
+ final class Baz3 extends Foo {
+ override def bar(x: Int) = x - 1
+ }
+
+ object Test {
+ // bar can't be inlined - it is overridden in Baz3
+ def f = Foo.mkFoo() bar 10
+ }
+}
+
+package neg2 {
+ sealed abstract class Foo {
+ @inline def bar(x: Int) = x + 1
+ }
+ object Foo {
+ def mkFoo(): Foo = new Baz2
+ }
+
+ object Baz1 extends Foo
+ final class Baz2 extends Foo
+ class Baz3 extends Foo {
+ override def bar(x: Int) = x - 1
+ }
+
+ object Test {
+ // bar can't be inlined - Baz3 is not final
+ def f = Foo.mkFoo() bar 10
+ }
+}
+
+"Due to SI-6142 this emits no warnings, so we'll just break it until that's fixed."