@@ -401,4 +401,49 @@ class TestBCode extends DottyBytecodeTest {
401401 }
402402 }
403403
404+ @ Test def returnThrowInPatternMatch = {
405+ val source =
406+ """ class Test {
407+ | def test(a: Any): Int = {
408+ | a match {
409+ | case _: Test => 1
410+ | }
411+ | }
412+ |}
413+ """ .stripMargin
414+
415+ checkBCode(source) { dir =>
416+ val moduleIn = dir.lookupName(" Test.class" , directory = false )
417+ val moduleNode = loadClassNode(moduleIn.input)
418+ val method = getMethod(moduleNode, " test" )
419+
420+ val instructions = instructionsFromMethod(method)
421+ val expected = List (
422+ VarOp (Opcodes .ALOAD , 1 ),
423+ VarOp (Opcodes .ASTORE , 2 ),
424+ VarOp (Opcodes .ALOAD , 2 ),
425+ TypeOp (Opcodes .INSTANCEOF , " Test" ),
426+ Jump (Opcodes .IFEQ , Label (10 )),
427+ VarOp (Opcodes .ALOAD , 2 ),
428+ TypeOp (Opcodes .CHECKCAST , " Test" ),
429+ VarOp (Opcodes .ASTORE , 3 ),
430+ Op (Opcodes .ICONST_1 ),
431+ Jump (Opcodes .GOTO , Label (17 )),
432+ Label (10 ),
433+ FrameEntry (1 , List (" java/lang/Object" ), List ()),
434+ TypeOp (Opcodes .NEW , " scala/MatchError" ),
435+ Op (Opcodes .DUP ),
436+ VarOp (Opcodes .ALOAD , 2 ),
437+ Invoke (Opcodes .INVOKESPECIAL , " scala/MatchError" , " <init>" , " (Ljava/lang/Object;)V" , false ),
438+ Op (Opcodes .ATHROW ),
439+ Label (17 ),
440+ FrameEntry (0 , List (" Test" , " java/lang/Object" , " java/lang/Object" , " Test" ), List (1 )),
441+ Op (Opcodes .IRETURN )
442+ )
443+ assert(instructions == expected,
444+ " `test` was not properly generated\n " + diffInstructions(instructions, expected))
445+
446+ }
447+ }
448+
404449}
0 commit comments