Skip to content

Commit 48e27fe

Browse files
committed
Add InlineBytecodeTests for #6375
1 parent 9daeaa0 commit 48e27fe

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,40 @@ class InlineBytecodeTests extends DottyBytecodeTest {
320320

321321
}
322322
}
323+
324+
@Test def i6375 = {
325+
val source = """class Test:
326+
| given Int = 0
327+
| def f(): Int ?=> Boolean = true : (Int ?=> Boolean)
328+
| inline def g(): Int ?=> Boolean = true
329+
| def test = g()
330+
""".stripMargin
331+
332+
checkBCode(source) { dir =>
333+
val clsIn = dir.lookupName("Test.class", directory = false).input
334+
val clsNode = loadClassNode(clsIn)
335+
336+
val fun = getMethod(clsNode, "test")
337+
val instructions = instructionsFromMethod(fun)
338+
val expected =
339+
List(
340+
// Head tested separatly
341+
VarOp(ALOAD, 0),
342+
Invoke(INVOKEVIRTUAL, "Test", "given_Int", "()I", false),
343+
Invoke(INVOKESTATIC, "scala/runtime/BoxesRunTime", "boxToInteger", "(I)Ljava/lang/Integer;", false),
344+
Invoke(INVOKEINTERFACE, "scala/Function1", "apply", "(Ljava/lang/Object;)Ljava/lang/Object;", true),
345+
Invoke(INVOKESTATIC, "scala/runtime/BoxesRunTime", "unboxToBoolean", "(Ljava/lang/Object;)Z", false),
346+
Op(IRETURN)
347+
)
348+
349+
instructions.head match {
350+
case InvokeDynamic(INVOKEDYNAMIC, "apply$mcZI$sp", "()Ldotty/runtime/function/JFunction1$mcZI$sp;", _, _) =>
351+
case _ => assert(false, "`g` was not properly inlined in `test`\n")
352+
}
353+
354+
assert(instructions.tail == expected,
355+
"`fg was not properly inlined in `test`\n" + diffInstructions(instructions, expected))
356+
357+
}
358+
}
323359
}

0 commit comments

Comments
 (0)