Skip to content

Commit 5add130

Browse files
authored
Merge pull request #5060 from dotty-staging/fix-#4522
Fix #4522: Add a regression test
2 parents bb322b0 + 7f9b5d2 commit 5add130

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,43 @@ 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 test: Int = {
289+
| var a = 10
290+
|
291+
| rewrite def f() = {
292+
| a += 1
293+
| }
294+
|
295+
| f()
296+
| a
297+
| }
298+
|}
299+
""".stripMargin
300+
301+
checkBCode(source) { dir =>
302+
val clsIn = dir.lookupName("Foo.class", directory = false).input
303+
val clsNode = loadClassNode(clsIn)
304+
305+
val fun = getMethod(clsNode, "test")
306+
val instructions = instructionsFromMethod(fun)
307+
val expected =
308+
List(
309+
IntOp(BIPUSH, 10)
310+
, VarOp(ISTORE, 1)
311+
, VarOp(ILOAD, 1)
312+
, Op(ICONST_1)
313+
, Op(IADD)
314+
, VarOp(ISTORE, 1)
315+
, VarOp(ILOAD, 1)
316+
, Op(IRETURN)
317+
)
318+
assert(instructions == expected,
319+
"`f` was not properly inlined in `fun`\n" + diffInstructions(instructions, expected))
320+
321+
}
322+
}
284323
}

0 commit comments

Comments
 (0)