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