diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2015-02-02 21:04:49 +0100 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2015-02-07 07:45:49 +0100 |
commit | 1437aa88241d5e99900a86b25c6ce385c2708570 (patch) | |
tree | e026a19cb5ed382fc8f2b697045cf4dd5d7c372e /test/files/jvm | |
parent | 0bcc871e3f4c4331fb53ec0e7087669589a607d6 (diff) | |
download | scala-1437aa88241d5e99900a86b25c6ce385c2708570.tar.gz scala-1437aa88241d5e99900a86b25c6ce385c2708570.tar.bz2 scala-1437aa88241d5e99900a86b25c6ce385c2708570.zip |
SI-9124 fix EnclosingMethod of classes nested in implOnly trait defs
Private trait methods are not added to the generated interface, they
end up only in the implementation class. For classes nested in such
methods, the EnclosingMethod attribute was incorrect.
Since the EnclosingMethod attribute expresses a source-level property,
but the actual enclosing method does not exist in the bytecode, we
set the enclosing method to null.
Diffstat (limited to 'test/files/jvm')
-rw-r--r-- | test/files/jvm/innerClassAttribute/Classes_1.scala | 17 | ||||
-rw-r--r-- | test/files/jvm/innerClassAttribute/Test.scala | 31 |
2 files changed, 48 insertions, 0 deletions
diff --git a/test/files/jvm/innerClassAttribute/Classes_1.scala b/test/files/jvm/innerClassAttribute/Classes_1.scala index a2ade70c18..7b5f5d93b9 100644 --- a/test/files/jvm/innerClassAttribute/Classes_1.scala +++ b/test/files/jvm/innerClassAttribute/Classes_1.scala @@ -223,3 +223,20 @@ class SI_9105 { val f: Object = { class L; new L } // closure null (*) SI_9105 bnM } } + +trait SI_9124 { + trait A // member class, no enclosing method attribute + + new A { def f1 = 0 } // nested class, enclosing class SI_9124, no encl meth + + def f = new A { def f2 = 0 } // enclosing method is f in the interface SI_9124 + + private def g = new A { def f3 = 0 } // only encl class (SI_9124), encl meth is null because the interface SI_9124 doesn't have a method g + + object O { // member, no encl meth attribute + new A { def f4 = 0 } // enclosing class is O$, no enclosing method + } + + val f1 = { new A { def f5 = 0 }; 1 } // encl class SI_9124, no encl meth + private val f2 = { new A { def f6 = 0 }; 1 } // like above +} diff --git a/test/files/jvm/innerClassAttribute/Test.scala b/test/files/jvm/innerClassAttribute/Test.scala index 30dc412ff7..5dacd2d830 100644 --- a/test/files/jvm/innerClassAttribute/Test.scala +++ b/test/files/jvm/innerClassAttribute/Test.scala @@ -393,6 +393,36 @@ object Test extends BytecodeTest { } } + def testSI_9124() { + val classes: Map[String, String] = { + List("SI_9124$$anon$10", + "SI_9124$$anon$11", + "SI_9124$$anon$12", + "SI_9124$$anon$8", + "SI_9124$$anon$9", + "SI_9124$O$$anon$13").map({ name => + val node = loadClassNode(name) + val fMethod = node.methods.asScala.find(_.name.startsWith("f")).get.name + (fMethod, node.name) + }).toMap + } + + // println(classes) + + assertNoEnclosingMethod("SI_9124$A") + assertEnclosingMethod(classes("f1"), "SI_9124", null, null) + assertEnclosingMethod(classes("f2"), "SI_9124", "f", "()LSI_9124$A;") + assertEnclosingMethod(classes("f3"), "SI_9124", null, null) + assertEnclosingMethod(classes("f4"), "SI_9124$O$", null, null) + assertEnclosingMethod(classes("f5"), "SI_9124", null, null) + assertEnclosingMethod(classes("f6"), "SI_9124", null, null) + assertNoEnclosingMethod("SI_9124$O$") + + assertMember(ownInnerClassNode("SI_9124$A"), "SI_9124", "A", flags = publicAbstractInterface) + classes.values.foreach(n => assertAnonymous(ownInnerClassNode(n), n)) + assertMember(ownInnerClassNode("SI_9124$O$"), "SI_9124", "O$") + } + def show(): Unit = { testA1() testA2() @@ -417,5 +447,6 @@ object Test extends BytecodeTest { testA23() testA24() testSI_9105() + testSI_9124() } } |