Skip to content

Commit cc6ca5f

Browse files
committed
Use local method
1 parent e21ae3f commit cc6ca5f

File tree

1 file changed

+41
-37
lines changed

1 file changed

+41
-37
lines changed

compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,18 @@ class InlineBytecodeTests extends DottyBytecodeTest {
4545
@Test def i4947 = {
4646
val source = """class Foo {
4747
| transparent def track[T](f: => T): T = {
48-
| println("tracking") // line 3
48+
| foo("tracking") // line 3
4949
| f // line 4
5050
| }
5151
| def main(args: Array[String]): Unit = { // line 6
5252
| track { // line 7
53-
| println("abc") // line 8
53+
| foo("abc") // line 8
5454
| track { // line 9
55-
| println("inner") // line 10
55+
| foo("inner") // line 10
5656
| }
5757
| } // line 11
5858
| }
59+
| def foo(str: String): Unit = ()
5960
|}
6061
""".stripMargin
6162

@@ -73,24 +74,24 @@ class InlineBytecodeTests extends DottyBytecodeTest {
7374
Label(0),
7475
LineNumber(6, Label(0)),
7576
LineNumber(3, Label(0)),
76-
Field(GETSTATIC, "scala/Predef$", "MODULE$", "Lscala/Predef$;"),
77+
VarOp(ALOAD, 0),
7778
Ldc(LDC, "tracking"),
78-
Invoke(INVOKEVIRTUAL, "scala/Predef$", "println", "(Ljava/lang/Object;)V", false),
79+
Invoke(INVOKEVIRTUAL, "Foo", "foo", "(Ljava/lang/String;)V", false),
7980
Label(6),
8081
LineNumber(8, Label(6)),
81-
Field(GETSTATIC, "scala/Predef$", "MODULE$", "Lscala/Predef$;"),
82+
VarOp(ALOAD, 0),
8283
Ldc(LDC, "abc"),
83-
Invoke(INVOKEVIRTUAL, "scala/Predef$", "println","(Ljava/lang/Object;)V", false),
84+
Invoke(INVOKEVIRTUAL, "Foo", "foo", "(Ljava/lang/String;)V", false),
8485
Label(11),
8586
LineNumber(3, Label(11)),
86-
Field(GETSTATIC, "scala/Predef$", "MODULE$", "Lscala/Predef$;"),
87+
VarOp(ALOAD, 0),
8788
Ldc(LDC, "tracking"),
88-
Invoke(INVOKEVIRTUAL, "scala/Predef$", "println","(Ljava/lang/Object;)V", false),
89+
Invoke(INVOKEVIRTUAL, "Foo", "foo", "(Ljava/lang/String;)V", false),
8990
Label(16),
9091
LineNumber(10, Label(16)),
91-
Field(GETSTATIC, "scala/Predef$", "MODULE$", "Lscala/Predef$;"),
92+
VarOp(ALOAD, 0),
9293
Ldc(LDC, "inner"),
93-
Invoke(INVOKEVIRTUAL, "scala/Predef$", "println","(Ljava/lang/Object;)V", false),
94+
Invoke(INVOKEVIRTUAL, "Foo", "foo", "(Ljava/lang/String;)V", false),
9495
Op(RETURN),
9596
Label(22)
9697
)
@@ -103,20 +104,21 @@ class InlineBytecodeTests extends DottyBytecodeTest {
103104
@Test def i4947b = {
104105
val source = """class Foo {
105106
| transparent def track2[T](f: => T): T = {
106-
| println("tracking2") // line 3
107+
| foo("tracking2") // line 3
107108
| f // line 4
108109
| }
109110
| transparent def track[T](f: => T): T = {
110-
| println("tracking") // line 7
111+
| foo("tracking") // line 7
111112
| track2 { // line 8
112113
| f // line 9
113114
| }
114115
| }
115116
| def main(args: Array[String]): Unit = { // line 12
116117
| track { // line 13
117-
| println("abc") // line 14
118+
| foo("abc") // line 14
118119
| }
119120
| }
121+
| def foo(str: String): Unit = ()
120122
|}
121123
""".stripMargin
122124

@@ -137,19 +139,19 @@ class InlineBytecodeTests extends DottyBytecodeTest {
137139
Label(0),
138140
LineNumber(12, Label(0)),
139141
LineNumber(7, Label(0)),
140-
Field(GETSTATIC, "scala/Predef$", "MODULE$", "Lscala/Predef$;"),
142+
VarOp(ALOAD, 0),
141143
Ldc(LDC, "tracking"),
142-
Invoke(INVOKEVIRTUAL, "scala/Predef$", "println", "(Ljava/lang/Object;)V", false),
144+
Invoke(INVOKEVIRTUAL, "Foo", "foo", "(Ljava/lang/String;)V", false),
143145
Label(6),
144146
LineNumber(3, Label(6)),
145-
Field(GETSTATIC, "scala/Predef$", "MODULE$", "Lscala/Predef$;"),
147+
VarOp(ALOAD, 0),
146148
Ldc(LDC, "tracking2"),
147-
Invoke(INVOKEVIRTUAL, "scala/Predef$", "println","(Ljava/lang/Object;)V", false),
149+
Invoke(INVOKEVIRTUAL, "Foo", "foo", "(Ljava/lang/String;)V", false),
148150
Label(11),
149151
LineNumber(14, Label(11)),
150-
Field(GETSTATIC, "scala/Predef$", "MODULE$", "Lscala/Predef$;"),
152+
VarOp(ALOAD, 0),
151153
Ldc(LDC, "abc"),
152-
Invoke(INVOKEVIRTUAL, "scala/Predef$", "println","(Ljava/lang/Object;)V", false),
154+
Invoke(INVOKEVIRTUAL, "Foo", "foo", "(Ljava/lang/String;)V", false),
153155
Op(RETURN),
154156
Label(17)
155157
)
@@ -162,20 +164,21 @@ class InlineBytecodeTests extends DottyBytecodeTest {
162164
@Test def i4947c = {
163165
val source = """class Foo {
164166
| transparent def track2[T](f: => T): T = {
165-
| println("tracking2") // line 3
167+
| foo("tracking2") // line 3
166168
| f // line 4
167169
| }
168170
| transparent def track[T](f: => T): T = {
169171
| track2 { // line 7
170-
| println("fgh") // line 8
172+
| foo("fgh") // line 8
171173
| f // line 9
172174
| }
173175
| }
174176
| def main(args: Array[String]): Unit = { // line 12
175177
| track { // line 13
176-
| println("abc") // line 14
178+
| foo("abc") // line 14
177179
| }
178180
| }
181+
| def foo(str: String): Unit = ()
179182
|}
180183
""".stripMargin
181184

@@ -196,19 +199,19 @@ class InlineBytecodeTests extends DottyBytecodeTest {
196199
Label(0),
197200
LineNumber(12, Label(0)),
198201
LineNumber(3, Label(0)),
199-
Field(GETSTATIC, "scala/Predef$", "MODULE$", "Lscala/Predef$;"),
202+
VarOp(ALOAD, 0),
200203
Ldc(LDC, "tracking2"),
201-
Invoke(INVOKEVIRTUAL, "scala/Predef$", "println", "(Ljava/lang/Object;)V", false),
204+
Invoke(INVOKEVIRTUAL, "Foo", "foo", "(Ljava/lang/String;)V", false),
202205
Label(6),
203206
LineNumber(8, Label(6)),
204-
Field(GETSTATIC, "scala/Predef$", "MODULE$", "Lscala/Predef$;"),
207+
VarOp(ALOAD, 0),
205208
Ldc(LDC, "fgh"),
206-
Invoke(INVOKEVIRTUAL, "scala/Predef$", "println","(Ljava/lang/Object;)V", false),
209+
Invoke(INVOKEVIRTUAL, "Foo", "foo", "(Ljava/lang/String;)V", false),
207210
Label(11),
208211
LineNumber(14, Label(11)),
209-
Field(GETSTATIC, "scala/Predef$", "MODULE$", "Lscala/Predef$;"),
212+
VarOp(ALOAD, 0),
210213
Ldc(LDC, "abc"),
211-
Invoke(INVOKEVIRTUAL, "scala/Predef$", "println","(Ljava/lang/Object;)V", false),
214+
Invoke(INVOKEVIRTUAL, "Foo", "foo", "(Ljava/lang/String;)V", false),
212215
Op(RETURN),
213216
Label(17)
214217
)
@@ -221,7 +224,7 @@ class InlineBytecodeTests extends DottyBytecodeTest {
221224
@Test def i4947d = {
222225
val source = """class Foo {
223226
| transparent def track2[T](f: => T): T = {
224-
| println("tracking2") // line 3
227+
| foo("tracking2") // line 3
225228
| f // line 4
226229
| }
227230
| transparent def track[T](f: => T): T = {
@@ -233,9 +236,10 @@ class InlineBytecodeTests extends DottyBytecodeTest {
233236
| }
234237
| def main(args: Array[String]): Unit = { // line 13
235238
| track { // line 14
236-
| println("abc") // line 15
239+
| foo("abc") // line 15
237240
| }
238241
| }
242+
| def foo(str: String): Unit = ()
239243
|}
240244
""".stripMargin
241245

@@ -256,19 +260,19 @@ class InlineBytecodeTests extends DottyBytecodeTest {
256260
Label(0),
257261
LineNumber(13, Label(0)),
258262
LineNumber(3, Label(0)),
259-
Field(GETSTATIC, "scala/Predef$", "MODULE$", "Lscala/Predef$;"),
263+
VarOp(ALOAD, 0),
260264
Ldc(LDC, "tracking2"),
261-
Invoke(INVOKEVIRTUAL, "scala/Predef$", "println", "(Ljava/lang/Object;)V", false),
265+
Invoke(INVOKEVIRTUAL, "Foo", "foo", "(Ljava/lang/String;)V", false),
262266
Label(6),
263267
LineNumber(3, Label(6)),
264-
Field(GETSTATIC, "scala/Predef$", "MODULE$", "Lscala/Predef$;"),
268+
VarOp(ALOAD, 0),
265269
Ldc(LDC, "tracking2"),
266-
Invoke(INVOKEVIRTUAL, "scala/Predef$", "println", "(Ljava/lang/Object;)V", false),
270+
Invoke(INVOKEVIRTUAL, "Foo", "foo", "(Ljava/lang/String;)V", false),
267271
Label(11),
268272
LineNumber(15, Label(11)),
269-
Field(GETSTATIC, "scala/Predef$", "MODULE$", "Lscala/Predef$;"),
273+
VarOp(ALOAD, 0),
270274
Ldc(LDC, "abc"),
271-
Invoke(INVOKEVIRTUAL, "scala/Predef$", "println","(Ljava/lang/Object;)V", false),
275+
Invoke(INVOKEVIRTUAL, "Foo", "foo", "(Ljava/lang/String;)V", false),
272276
Op(RETURN),
273277
Label(17)
274278
)

0 commit comments

Comments
 (0)