@@ -649,4 +649,50 @@ class TestBCode extends DottyBytecodeTest {
649649 assertFalse(boxUnit)
650650 }
651651 }
652+
653+ @ Test def i3271 = {
654+ val source =
655+ """ class Test {
656+ | def test = {
657+ | var x = 0
658+ | while(x <= 5) {
659+ | println(x)
660+ | x += 1
661+ | }
662+ | }
663+ |}
664+ """ .stripMargin
665+
666+ checkBCode(source) { dir =>
667+ val clsIn = dir.lookupName(" Test.class" , directory = false ).input
668+ val clsNode = loadClassNode(clsIn)
669+ val method = getMethod(clsNode, " test" )
670+
671+ val instructions = instructionsFromMethod(method)
672+
673+ val expected = List (
674+ Op (Opcodes .ICONST_0 ),
675+ VarOp (Opcodes .ISTORE , 1 ),
676+ Label (2 ),
677+ FrameEntry (1 , List (1 ), List ()),
678+ VarOp (Opcodes .ILOAD , 1 ),
679+ Op (Opcodes .ICONST_5 ),
680+ Jump (Opcodes .IF_ICMPGT , Label (16 )),
681+ Field (Opcodes .GETSTATIC , " scala/Predef$" , " MODULE$" , " Lscala/Predef$;" ),
682+ VarOp (Opcodes .ILOAD , 1 ),
683+ Invoke (Opcodes .INVOKESTATIC , " scala/runtime/BoxesRunTime" , " boxToInteger" , " (I)Ljava/lang/Integer;" , false ),
684+ Invoke (Opcodes .INVOKEVIRTUAL , " scala/Predef$" , " println" , " (Ljava/lang/Object;)V" , false ),
685+ VarOp (Opcodes .ILOAD , 1 ),
686+ Op (Opcodes .ICONST_1 ),
687+ Op (Opcodes .IADD ),
688+ VarOp (Opcodes .ISTORE , 1 ),
689+ Jump (Opcodes .GOTO , Label (2 )),
690+ Label (16 ),
691+ FrameEntry (3 , List (), List ()),
692+ Op (Opcodes .RETURN ))
693+
694+ assert(instructions == expected,
695+ " `test` was not properly generated\n " + diffInstructions(instructions, expected))
696+ }
697+ }
652698}
0 commit comments