From b2e22fa308b2f402d78dc3d3afc33256c1d3cbba Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Tue, 3 Feb 2015 11:29:08 +0100 Subject: 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). --- test/files/jvm/innerClassAttribute.check | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/files/jvm/innerClassAttribute.check') diff --git a/test/files/jvm/innerClassAttribute.check b/test/files/jvm/innerClassAttribute.check index 8395ff0b09..bb532e4f36 100644 --- a/test/files/jvm/innerClassAttribute.check +++ b/test/files/jvm/innerClassAttribute.check @@ -30,11 +30,11 @@ fun4: () => 1: itself and the two outer closures A20$$anonfun$6 / null / null / 17 A20$$anonfun$6$$anonfun$apply$3 / null / null / 17 A20$$anonfun$6$$anonfun$apply$3$$anonfun$apply$2 / null / null / 17 -enclosing: nested closures have the apply method of the outer closure +enclosing: nested closures have outer class defined, but no outer method A20 / null / null -A20$$anonfun$6 / apply / ()Lscala/Function0; -A20$$anonfun$6 / apply / ()Lscala/Function0; -A20$$anonfun$6$$anonfun$apply$3 / apply / ()Lscala/Function0; +A20$$anonfun$6 / null / null +A20$$anonfun$6 / null / null +A20$$anonfun$6$$anonfun$apply$3 / null / null #partest -Ydelambdafy:method -- A4 -- null / null / null @@ -47,7 +47,7 @@ fun1: attribute for itself and the two child closures `() => ()` and `() => () = fun2 () => (): itself and the outer closure fun3 () => () => (): itself, the outer closure and its child closure fun4: () => 1: itself and the two outer closures -enclosing: nested closures have the apply method of the outer closure +enclosing: nested closures have outer class defined, but no outer method null / null / null null / null / null null / null / null -- cgit v1.2.3