Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit 2be2c0d

Browse files
retronymlrytz
authored andcommitted
Make two tests work under -Ydelambdafy:method
Recently, in 029cce7, I changed uncurry to selectively fallback to the old method of emitting lambdas when we detect that `-Ydelambdafy:method`. The change in classfile names breaks the expectations of the test `innerClassAttribute`. This commit changes that test to avoid using specialized functions, so that under -Ydelambdafy:method all functions are uniform. This changes a few fresh suffixes for anonymous class names under both `-Ydelambdafy:{inline,method}`, so the expectations have been duly updated. Similarly, I have changed `javaReflection` in the same manner. Its checkfiles remained unchanged.
1 parent 1f5c3f8 commit 2be2c0d

File tree

4 files changed

+66
-61
lines changed

4 files changed

+66
-61
lines changed

test/files/jvm/innerClassAttribute.check

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@ A19 / null / null
1414
A19 / null / null
1515
A19 / null / null
1616
-- A20 --
17-
A20$$anonfun$6 / null / null / 17
17+
A20$$anonfun$4 / null / null / 17
1818
fun1: attribute for itself and the two child closures `() => ()` and `() => () => 1`
19-
A20$$anonfun$6 / null / null / 17
20-
A20$$anonfun$6$$anonfun$apply$1 / null / null / 17
21-
A20$$anonfun$6$$anonfun$apply$3 / null / null / 17
19+
A20$$anonfun$4 / null / null / 17
20+
A20$$anonfun$4$$anonfun$apply$1 / null / null / 17
21+
A20$$anonfun$4$$anonfun$apply$2 / null / null / 17
2222
fun2 () => (): itself and the outer closure
23-
A20$$anonfun$6 / null / null / 17
24-
A20$$anonfun$6$$anonfun$apply$1 / null / null / 17
23+
A20$$anonfun$4 / null / null / 17
24+
A20$$anonfun$4$$anonfun$apply$1 / null / null / 17
2525
fun3 () => () => (): itself, the outer closure and its child closure
26-
A20$$anonfun$6 / null / null / 17
27-
A20$$anonfun$6$$anonfun$apply$3 / null / null / 17
28-
A20$$anonfun$6$$anonfun$apply$3$$anonfun$apply$2 / null / null / 17
26+
A20$$anonfun$4 / null / null / 17
27+
A20$$anonfun$4$$anonfun$apply$2 / null / null / 17
28+
A20$$anonfun$4$$anonfun$apply$2$$anonfun$apply$3 / null / null / 17
2929
fun4: () => 1: itself and the two outer closures
30-
A20$$anonfun$6 / null / null / 17
31-
A20$$anonfun$6$$anonfun$apply$3 / null / null / 17
32-
A20$$anonfun$6$$anonfun$apply$3$$anonfun$apply$2 / null / null / 17
30+
A20$$anonfun$4 / null / null / 17
31+
A20$$anonfun$4$$anonfun$apply$2 / null / null / 17
32+
A20$$anonfun$4$$anonfun$apply$2$$anonfun$apply$3 / null / null / 17
3333
enclosing: nested closures have outer class defined, but no outer method
3434
A20 / null / null
35-
A20$$anonfun$6 / null / null
36-
A20$$anonfun$6 / null / null
37-
A20$$anonfun$6$$anonfun$apply$3 / null / null
35+
A20$$anonfun$4 / null / null
36+
A20$$anonfun$4 / null / null
37+
A20$$anonfun$4$$anonfun$apply$2 / null / null
3838
#partest -Ydelambdafy:method
3939
-- A4 --
4040
null / null / null

test/files/jvm/innerClassAttribute/Classes_1.scala

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ object A3 {
1212
}
1313

1414
class A4 {
15-
def f(l: List[Int]): List[Int] = {
16-
l map (_ + 1)
15+
def f(l: List[String]): List[String] = {
16+
l map (_ + "1")
1717
}
1818
}
1919

@@ -114,21 +114,21 @@ class A18 {
114114
}
115115

116116
class A19 {
117-
((x: Int) => x + 3)
117+
((x: String) => x + "3")
118118

119119
val x = {
120-
((x: Int) => x + 1)
120+
((x: String) => x + "1")
121121
}
122122

123123
{
124-
((x: Int) => x + 2)
124+
((x: String) => x + "2")
125125
}
126126
}
127127

128128
class A20 {
129-
() => {
130-
{() => ()}
131-
{() => () => 1}
129+
(s: String) => {
130+
{(s: String) => ()}
131+
{(s: String) => (s: String) => 1}
132132
}
133133
}
134134

@@ -189,13 +189,13 @@ trait A24 extends A24Base {
189189
class SI_9105 {
190190
// the EnclosingMethod attributes depend on the delambdafy strategy (inline vs method)
191191

192-
// outerClass-inline enclMeth-inline outerClass-method enclMeth-method
193-
val fun = () => {
192+
// outerClass-inline enclMeth-inline outerClass-method enclMeth-method
193+
val fun = (s: String) => {
194194
class A // closure null (*) SI_9105 null
195195
def m: Object = { class B; new B } // closure m$1 SI_9105 m$1
196196
val f: Object = { class C; new C } // closure null (*) SI_9105 null
197197
}
198-
def met = () => {
198+
def met = (s: String) => {
199199
class D // closure null (*) SI_9105 met
200200
def m: Object = { class E; new E } // closure m$1 SI_9105 m$1
201201
val f: Object = { class F; new F } // closure null (*) SI_9105 met
@@ -210,17 +210,19 @@ class SI_9105 {
210210
// So using `null` looks more like the situation in the source code: C / F are nested classes of the anon-fun, and
211211
// there's no method in between.
212212

213-
def byName[T](op: => T) = 0
213+
def byName(op: => Any) = 0
214214

215215
val bnV = byName {
216216
class G // closure null (*) SI_9105 null
217217
def m: Object = { class H; new H } // closure m$1 SI_9105 m$1
218218
val f: Object = { class I; new I } // closure null (*) SI_9105 null
219+
""
219220
}
220221
def bnM = byName {
221222
class J // closure null (*) SI_9105 bnM
222223
def m: Object = { class K; new K } // closure m$1 SI_9105 m$1
223224
val f: Object = { class L; new L } // closure null (*) SI_9105 bnM
225+
""
224226
}
225227
}
226228

@@ -283,8 +285,8 @@ object NestedInValueClass {
283285
class A(val arg: String) extends AnyVal {
284286
// A has InnerClass entries for the two closures (and for A and A$). not for B / C
285287
def f = {
286-
def g = List().map(x => (() => x)) // outer class A, no outer method (g is moved to the companion, doesn't exist in A)
287-
g.map(x => (() => x)) // outer class A, outer method f
288+
def g = List().map(x => ((s: String) => x)) // outer class A, no outer method (g is moved to the companion, doesn't exist in A)
289+
g.map(x => ((s: String) => x)) // outer class A, outer method f
288290
}
289291
// statements and field declarations are not allowed in value classes
290292
}

test/files/jvm/innerClassAttribute/Test.scala

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ import asm.{Opcodes => Flags}
55
import scala.collection.JavaConverters._
66

77
object Test extends BytecodeTest {
8+
// Helpful for debugging the test:
9+
// println(new java.io.File(classpath.asURLs.head.toURI).list().sorted.mkString("\n"))
10+
811
def assertSame(a: Any, b: Any) = {
912
assert(a == b, s"\na: $a\nb: $b")
1013
}
1114

12-
val publicStatic = Flags.ACC_PUBLIC | Flags.ACC_STATIC
15+
val publicStatic = Flags.ACC_PUBLIC | Flags.ACC_STATIC
1316
val publicAbstractInterface = Flags.ACC_PUBLIC | Flags.ACC_ABSTRACT | Flags.ACC_INTERFACE
1417

1518
def innerClassNodes(className: String): List[InnerClassNode] = {
@@ -266,10 +269,10 @@ object Test extends BytecodeTest {
266269

267270
printInnerClassNodes("A20")
268271

269-
val fun1 = lambdaClass("A20$$anonfun$6", "A20$lambda$1")
270-
val fun2 = lambdaClass("A20$$anonfun$6$$anonfun$apply$1", "A20$lambda$$$nestedInAnonfun$5$1")
271-
val fun3 = lambdaClass("A20$$anonfun$6$$anonfun$apply$3", "A20$lambda$$$nestedInAnonfun$5$2")
272-
val fun4 = lambdaClass("A20$$anonfun$6$$anonfun$apply$3$$anonfun$apply$2", "A20$lambda$$$nestedInAnonfun$7$1")
272+
val fun1 = lambdaClass("A20$$anonfun$4", "A20$lambda$1")
273+
val fun2 = lambdaClass("A20$$anonfun$4$$anonfun$apply$1", "A20$lambda$$$nestedInAnonfun$5$1")
274+
val fun3 = lambdaClass("A20$$anonfun$4$$anonfun$apply$2", "A20$lambda$$$nestedInAnonfun$5$2")
275+
val fun4 = lambdaClass("A20$$anonfun$4$$anonfun$apply$2$$anonfun$apply$3", "A20$lambda$$$nestedInAnonfun$7$1")
273276

274277
println("fun1: attribute for itself and the two child closures `() => ()` and `() => () => 1`")
275278
printInnerClassNodes(fun1)
@@ -339,9 +342,9 @@ object Test extends BytecodeTest {
339342
assertEnclosingMethod ("SI_9105$A$3" , "SI_9105", null , null)
340343
assertEnclosingMethod ("SI_9105$B$5" , "SI_9105", "m$1", "()Ljava/lang/Object;")
341344
assertEnclosingMethod ("SI_9105$C$1" , "SI_9105", null , null)
342-
assertEnclosingMethod ("SI_9105$D$1" , "SI_9105", "met", "()Lscala/Function0;")
345+
assertEnclosingMethod ("SI_9105$D$1" , "SI_9105", "met", "()Lscala/Function1;")
343346
assertEnclosingMethod ("SI_9105$E$1" , "SI_9105", "m$3", "()Ljava/lang/Object;")
344-
assertEnclosingMethod ("SI_9105$F$1" , "SI_9105", "met", "()Lscala/Function0;")
347+
assertEnclosingMethod ("SI_9105$F$1" , "SI_9105", "met", "()Lscala/Function1;")
345348
assertNoEnclosingMethod("SI_9105$lambda$$met$1")
346349
assertNoEnclosingMethod("SI_9105$lambda$1")
347350
assertNoEnclosingMethod("SI_9105")
@@ -366,35 +369,35 @@ object Test extends BytecodeTest {
366369
assert(innerClassNodes("SI_9105").length == 12) // the 12 local classes
367370
} else {
368371
// comment in innerClassAttribute/Classes_1.scala explains the difference between A / C and D / F.
369-
assertEnclosingMethod ("SI_9105$$anonfun$4$A$3" , "SI_9105$$anonfun$4" , null , null)
370-
assertEnclosingMethod ("SI_9105$$anonfun$4$B$5" , "SI_9105$$anonfun$4" , "m$1" , "()Ljava/lang/Object;")
371-
assertEnclosingMethod ("SI_9105$$anonfun$4$C$1" , "SI_9105$$anonfun$4" , null , null)
372+
assertEnclosingMethod ("SI_9105$$anonfun$5$A$3" , "SI_9105$$anonfun$5" , null , null)
373+
assertEnclosingMethod ("SI_9105$$anonfun$5$B$5" , "SI_9105$$anonfun$5" , "m$1" , "()Ljava/lang/Object;")
374+
assertEnclosingMethod ("SI_9105$$anonfun$5$C$1" , "SI_9105$$anonfun$5" , null , null)
372375
assertEnclosingMethod ("SI_9105$$anonfun$met$1$D$1", "SI_9105$$anonfun$met$1", null , null)
373376
assertEnclosingMethod ("SI_9105$$anonfun$met$1$E$1", "SI_9105$$anonfun$met$1", "m$3" , "()Ljava/lang/Object;")
374377
assertEnclosingMethod ("SI_9105$$anonfun$met$1$F$1", "SI_9105$$anonfun$met$1", null , null)
375-
assertEnclosingMethod ("SI_9105$$anonfun$4" , "SI_9105" , null , null)
376-
assertEnclosingMethod ("SI_9105$$anonfun$met$1" , "SI_9105" , "met" , "()Lscala/Function0;")
378+
assertEnclosingMethod ("SI_9105$$anonfun$5" , "SI_9105" , null , null)
379+
assertEnclosingMethod ("SI_9105$$anonfun$met$1" , "SI_9105" , "met" , "()Lscala/Function1;")
377380
assertNoEnclosingMethod("SI_9105")
378381

379-
assertLocal(ownInnerClassNode("SI_9105$$anonfun$4$A$3"), "SI_9105$$anonfun$4$A$3" , "A$3")
380-
assertLocal(ownInnerClassNode("SI_9105$$anonfun$4$B$5"), "SI_9105$$anonfun$4$B$5" , "B$5")
381-
assertLocal(ownInnerClassNode("SI_9105$$anonfun$4$C$1"), "SI_9105$$anonfun$4$C$1" , "C$1")
382+
assertLocal(ownInnerClassNode("SI_9105$$anonfun$5$A$3"), "SI_9105$$anonfun$5$A$3" , "A$3")
383+
assertLocal(ownInnerClassNode("SI_9105$$anonfun$5$B$5"), "SI_9105$$anonfun$5$B$5" , "B$5")
384+
assertLocal(ownInnerClassNode("SI_9105$$anonfun$5$C$1"), "SI_9105$$anonfun$5$C$1" , "C$1")
382385
assertLocal(ownInnerClassNode("SI_9105$$anonfun$met$1$D$1"), "SI_9105$$anonfun$met$1$D$1", "D$1")
383386
assertLocal(ownInnerClassNode("SI_9105$$anonfun$met$1$E$1"), "SI_9105$$anonfun$met$1$E$1", "E$1")
384387
assertLocal(ownInnerClassNode("SI_9105$$anonfun$met$1$F$1"), "SI_9105$$anonfun$met$1$F$1", "F$1")
385388

386389
// by-name
387-
assertEnclosingMethod("SI_9105$$anonfun$5$G$1", "SI_9105$$anonfun$5", null, null)
388-
assertEnclosingMethod("SI_9105$$anonfun$5$H$1", "SI_9105$$anonfun$5", "m$2", "()Ljava/lang/Object;")
389-
assertEnclosingMethod("SI_9105$$anonfun$5$I$1", "SI_9105$$anonfun$5", null, null)
390+
assertEnclosingMethod("SI_9105$$anonfun$6$G$1", "SI_9105$$anonfun$6", null, null)
391+
assertEnclosingMethod("SI_9105$$anonfun$6$H$1", "SI_9105$$anonfun$6", "m$2", "()Ljava/lang/Object;")
392+
assertEnclosingMethod("SI_9105$$anonfun$6$I$1", "SI_9105$$anonfun$6", null, null)
390393
assertEnclosingMethod("SI_9105$$anonfun$bnM$1$J$1", "SI_9105$$anonfun$bnM$1", null, null)
391394
assertEnclosingMethod("SI_9105$$anonfun$bnM$1$K$2", "SI_9105$$anonfun$bnM$1", "m$4", "()Ljava/lang/Object;")
392395
assertEnclosingMethod("SI_9105$$anonfun$bnM$1$L$1", "SI_9105$$anonfun$bnM$1", null, null)
393396

394-
assertAnonymous(ownInnerClassNode("SI_9105$$anonfun$4"), "SI_9105$$anonfun$4")
397+
assertAnonymous(ownInnerClassNode("SI_9105$$anonfun$5"), "SI_9105$$anonfun$5")
395398
assertAnonymous(ownInnerClassNode("SI_9105$$anonfun$met$1"), "SI_9105$$anonfun$met$1")
396399

397-
assert(innerClassNodes("SI_9105$$anonfun$4").length == 4) // itself and three of the local classes
400+
assert(innerClassNodes("SI_9105$$anonfun$5").length == 4) // itself and three of the local classes
398401
assert(innerClassNodes("SI_9105$$anonfun$met$1").length == 4) // itself and three of the local classes
399402
assert(innerClassNodes("SI_9105").length == 4) // the four anon funs
400403
}
@@ -474,7 +477,7 @@ object Test extends BytecodeTest {
474477
testInner("ImplClassesAreTopLevel$B2$1$class", b2)
475478
testInner("ImplClassesAreTopLevel$B3$1$class", b3)
476479
testInner("ImplClassesAreTopLevel$B4$class", b4)
477-
480+
478481
testInner("ImplClassesAreTopLevel$B1", b1)
479482
testInner("ImplClassesAreTopLevel$B2$1", b2)
480483
testInner("ImplClassesAreTopLevel$B3$1", b3)
@@ -533,13 +536,13 @@ object Test extends BytecodeTest {
533536
"NestedInValueClass$A$lambda$$g$2$1",
534537
"NestedInValueClass$A$lambda$$f$extension$1",
535538
"NestedInValueClass$A$lambda$$$nestedInAnonfun$13$1",
536-
"NestedInValueClass$A$lambda$$$nestedInAnonfun$15$1").foreach(assertNoEnclosingMethod)
539+
"NestedInValueClass$A$lambda$$NestedInValueClass$A$$$nestedInAnonfun$15$1").foreach(assertNoEnclosingMethod)
537540
testInner("NestedInValueClass$A", a, am)
538541
testInner("NestedInValueClass$A$", a, am, b, c)
539542
testInner("NestedInValueClass$A$lambda$$g$2$1", am)
540543
testInner("NestedInValueClass$A$lambda$$f$extension$1", am)
541544
testInner("NestedInValueClass$A$lambda$$$nestedInAnonfun$13$1", am)
542-
testInner("NestedInValueClass$A$lambda$$$nestedInAnonfun$15$1", am)
545+
testInner("NestedInValueClass$A$lambda$$NestedInValueClass$A$$$nestedInAnonfun$15$1", am)
543546
} else {
544547
assertEnclosingMethod("NestedInValueClass$A$$anonfun$g$2$1" , "NestedInValueClass$A" , null, null)
545548
assertEnclosingMethod("NestedInValueClass$A$$anonfun$g$2$1$$anonfun$apply$4" , "NestedInValueClass$A$$anonfun$g$2$1" , null, null)

test/files/jvm/javaReflection/Classes_1.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,29 @@ class A {
1313
trait C
1414
object D
1515
new T { }
16-
(() => -1)
16+
(() => "-1")
1717
def f = { class KB }
1818
}
1919

2020
// anonymous class, not a member
2121
new T { }
2222

2323
// anonymous function, not a member
24-
(() => 1)
24+
(() => "1")
2525

2626
def f = {
2727
class E
2828
trait F
2929
object G
3030
new T { }
31-
(() => 2)
31+
(() => "2")
3232

3333
if (new Object().hashCode == 1) {
3434
class H
3535
trait I
3636
object J
3737
new T { }
38-
(() => 3)
38+
(() => "3")
3939
} else {
4040
()
4141
}
@@ -46,15 +46,15 @@ class A {
4646
trait L
4747
object M
4848
new T { }
49-
(() => 4)
49+
(() => "4")
5050
}
5151

5252
val x = {
5353
class N
5454
trait O
5555
object P
5656
new T { }
57-
(() => 5)
57+
(() => "5")
5858
}
5959

6060
def this(x: Int) {
@@ -63,7 +63,7 @@ class A {
6363
trait R
6464
object S
6565
new T { }
66-
(() => () => 5)
66+
(() => () => "5")
6767
}
6868
}
6969

@@ -72,13 +72,13 @@ object AO {
7272
trait C
7373
object D
7474
new T { }
75-
(() => 1)
75+
(() => "1")
7676
}
7777

7878
trait AT {
7979
class B
8080
trait C
8181
object D
8282
new T { }
83-
(() => 1)
83+
(() => "1")
8484
}

0 commit comments

Comments
 (0)