@@ -418,4 +418,70 @@ class InlineBytecodeTests extends DottyBytecodeTest {
418418
419419 }
420420 }
421+
422+ @ Test def i6800a = {
423+ val source = """ class Foo:
424+ | inline def inlined(f: => Unit): Unit = f
425+ | def test: Unit = inlined { println("") }
426+ """ .stripMargin
427+
428+ checkBCode(source) { dir =>
429+ val clsIn = dir.lookupName(" Foo.class" , directory = false ).input
430+ val clsNode = loadClassNode(clsIn)
431+
432+ val fun = getMethod(clsNode, " test" )
433+ val instructions = instructionsFromMethod(fun)
434+ val expected = List (Invoke (INVOKESTATIC , " Foo" , " f$1" , " ()V" , false ), Op (RETURN ))
435+ assert(instructions == expected,
436+ " `inlined` was not properly inlined in `test`\n " + diffInstructions(instructions, expected))
437+
438+ }
439+ }
440+
441+ @ Test def i6800b = {
442+ val source = """ class Foo:
443+ | inline def printIfZero(x: Int): Unit = inline x match
444+ | case 0 => println("zero")
445+ | case _ => ()
446+ | def test: Unit = printIfZero(0)
447+ """ .stripMargin
448+
449+ checkBCode(source) { dir =>
450+ val clsIn = dir.lookupName(" Foo.class" , directory = false ).input
451+ val clsNode = loadClassNode(clsIn)
452+
453+ val fun = getMethod(clsNode, " test" )
454+ val instructions = instructionsFromMethod(fun)
455+ val expected = List (
456+ Field (GETSTATIC , " scala/Predef$" , " MODULE$" , " Lscala/Predef$;" ),
457+ Ldc (LDC , " zero" ),
458+ Invoke (INVOKEVIRTUAL , " scala/Predef$" , " println" , " (Ljava/lang/Object;)V" , false ),
459+ Op (RETURN )
460+ )
461+ assert(instructions == expected,
462+ " `printIfZero` was not properly inlined in `test`\n " + diffInstructions(instructions, expected))
463+ }
464+ }
465+
466+
467+ @ Test def i9246 = {
468+ val source = """ class Foo:
469+ | inline def check(v:Double): Unit = if(v==0) throw new Exception()
470+ | inline def divide(v: Double, d: Double): Double = { check(d); v / d }
471+ | def test = divide(10,2)
472+ """ .stripMargin
473+
474+ checkBCode(source) { dir =>
475+ val clsIn = dir.lookupName(" Foo.class" , directory = false ).input
476+ val clsNode = loadClassNode(clsIn)
477+
478+ val fun = getMethod(clsNode, " test" )
479+ val instructions = instructionsFromMethod(fun)
480+ val expected = List (Ldc (LDC , 5.0 ), Op (DRETURN ))
481+ assert(instructions == expected,
482+ " `divide` was not properly inlined in `test`\n " + diffInstructions(instructions, expected))
483+
484+ }
485+ }
486+
421487}
0 commit comments