diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2015-02-03 11:29:08 +0100 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2015-02-07 07:45:53 +0100 |
commit | b2e22fa308b2f402d78dc3d3afc33256c1d3cbba (patch) | |
tree | e7bdb44726dd50866465af28618f643ab391867b /test/files/jvm/innerClassAttribute/Classes_1.scala | |
parent | cd8f2f327106c7e2944afa7ac8b7675262626c1e (diff) | |
download | scala-b2e22fa308b2f402d78dc3d3afc33256c1d3cbba.tar.gz scala-b2e22fa308b2f402d78dc3d3afc33256c1d3cbba.tar.bz2 scala-b2e22fa308b2f402d78dc3d3afc33256c1d3cbba.zip |
Fix InnerClass / EnclosingMethod for closures nested in value classes
Members of value classes are moved over to the companion object early.
This change ensures that closure classes nested in value classes
appear that way to Java reflection.
This commit also changes the EnclosingMethod attribute for classes
(and anonymous functions) nested in anonymous function bodies. Before,
the enclosing method was in some cases the function's apply method.
Not always though:
() => { class C ... val a = { class D ...} }
The class C used to be nested in the function's apply method, but not
D, because the value definition for a was lifted out of the apply.
After this commit, we uniformly set the enclosing method of classes
nested in function bodies to `null`. This is consistent with the
source-level view of the code.
Note that under delambdafy:method, closures never appear as enclosing
classes (this didn't change in this commit).
Diffstat (limited to 'test/files/jvm/innerClassAttribute/Classes_1.scala')
-rw-r--r-- | test/files/jvm/innerClassAttribute/Classes_1.scala | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/files/jvm/innerClassAttribute/Classes_1.scala b/test/files/jvm/innerClassAttribute/Classes_1.scala index e58fd6e26f..fb1f32aa3d 100644 --- a/test/files/jvm/innerClassAttribute/Classes_1.scala +++ b/test/files/jvm/innerClassAttribute/Classes_1.scala @@ -277,3 +277,21 @@ class SpecializedClassesAreTopLevel { // new D[Int] // } } + +object NestedInValueClass { + // note that we can only test anonymous functions, nested classes are not allowed inside value classes + class A(val arg: String) extends AnyVal { + // A has InnerClass entries for the two closures (and for A and A$). not for B / C + def f = { + def g = List().map(x => (() => x)) // outer class A, no outer method (g is moved to the companion, doesn't exist in A) + g.map(x => (() => x)) // outer class A, outer method f + } + // statements and field declarations are not allowed in value classes + } + + object A { + // A$ has InnerClass entries for B, C, A, A$. Also for the closures above, because they are referenced in A$'s bytecode. + class B // member class of A$ + def f = { class C; new C } // outer class A$, outer method f + } +} |