Skip to content

Commit c0fc53a

Browse files
committed
Fix #4522: add a regression test
1 parent 1d24eaa commit c0fc53a

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,51 @@ class InlineBytecodeTests extends DottyBytecodeTest {
281281

282282
}
283283
}
284+
285+
// Testing that a is not boxed
286+
@Test def i4522 = {
287+
val source = """class Foo {
288+
| def fun: Int = {
289+
| var a = 10
290+
| rewrite def f(arg: => Unit) = {
291+
| a += 1
292+
| arg
293+
| }
294+
|
295+
| f {
296+
| return a
297+
| }
298+
| a
299+
| }
300+
|}
301+
""".stripMargin
302+
303+
checkBCode(source) { dir =>
304+
val clsIn = dir.lookupName("Foo.class", directory = false).input
305+
val clsNode = loadClassNode(clsIn)
306+
307+
val fun = getMethod(clsNode, "fun")
308+
val instructions = instructionsFromMethod(fun)
309+
val expected =
310+
List(
311+
IntOp(BIPUSH, 10)
312+
, VarOp(ISTORE, 1)
313+
, VarOp(ILOAD, 1)
314+
, Op(ICONST_1)
315+
, Op(IADD)
316+
, VarOp(ISTORE, 1)
317+
, VarOp(ILOAD, 1)
318+
, Op(IRETURN)
319+
, Label(8)
320+
, FrameEntry(0, List(), List("java/lang/Throwable"))
321+
, Op(ATHROW)
322+
, Label(11)
323+
, FrameEntry(4, List(), List("java/lang/Throwable"))
324+
, Op(ATHROW)
325+
)
326+
assert(instructions == expected,
327+
"`f` was not properly inlined in `fun`\n" + diffInstructions(instructions, expected))
328+
329+
}
330+
}
284331
}

0 commit comments

Comments
 (0)