@@ -401,4 +401,53 @@ class TestBCode extends DottyBytecodeTest {
401
401
}
402
402
}
403
403
404
+ @ Test def returnThrowInPatternMatch = {
405
+ val source =
406
+ """ class Test {
407
+ | def test(a: Any): Int = {
408
+ | a match {
409
+ | case _: Test => ???
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 (11 )),
427
+ VarOp (Opcodes .ALOAD , 2 ),
428
+ TypeOp (Opcodes .CHECKCAST , " Test" ),
429
+ VarOp (Opcodes .ASTORE , 3 ),
430
+ Field (Opcodes .GETSTATIC , " scala/Predef$" , " MODULE$" , " Lscala/Predef$;" ),
431
+ Invoke (Opcodes .INVOKEVIRTUAL , " scala/Predef$" , " $qmark$qmark$qmark" , " ()Lscala/runtime/Nothing$;" , false ),
432
+ Op (Opcodes .ATHROW ),
433
+ Label (11 ),
434
+ FrameEntry (1 , List (" java/lang/Object" ), List ()),
435
+ TypeOp (Opcodes .NEW , " scala/MatchError" ),
436
+ Op (Opcodes .DUP ),
437
+ VarOp (Opcodes .ALOAD , 2 ),
438
+ Invoke (Opcodes .INVOKESPECIAL , " scala/MatchError" , " <init>" , " (Ljava/lang/Object;)V" , false ),
439
+ Op (Opcodes .ATHROW ),
440
+ Label (18 ),
441
+ FrameEntry (0 , List (), List (" java/lang/Throwable" )),
442
+ Op (Opcodes .ATHROW ),
443
+ Label (21 ),
444
+ FrameEntry (4 , List (), List (" java/lang/Throwable" )),
445
+ Op (Opcodes .ATHROW )
446
+ )
447
+ assert(instructions == expected,
448
+ " `test` was not properly generated\n " + diffInstructions(instructions, expected))
449
+
450
+ }
451
+ }
452
+
404
453
}
0 commit comments