Skip to content

Commit aabc81b

Browse files
committed
Make optimiation more general
1 parent f88c09b commit aabc81b

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ object PatternMatcher {
839839
default
840840
}
841841
case ResultPlan(tree) =>
842-
if (tree.symbol eq defn.throwMethod) tree // Namely MatchError
842+
if (tree.tpe <:< defn.NothingType) tree // Namely MatchError
843843
else Return(tree, ref(resultLabel))
844844
}
845845
}

compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ class TestBCode extends DottyBytecodeTest {
406406
"""class Test {
407407
| def test(a: Any): Int = {
408408
| a match {
409-
| case _: Test => 1
409+
| case _: Test => ???
410410
| }
411411
| }
412412
|}
@@ -423,22 +423,26 @@ class TestBCode extends DottyBytecodeTest {
423423
VarOp(Opcodes.ASTORE, 2),
424424
VarOp(Opcodes.ALOAD, 2),
425425
TypeOp(Opcodes.INSTANCEOF, "Test"),
426-
Jump(Opcodes.IFEQ, Label(10)),
426+
Jump(Opcodes.IFEQ, Label(11)),
427427
VarOp(Opcodes.ALOAD, 2),
428428
TypeOp(Opcodes.CHECKCAST, "Test"),
429429
VarOp(Opcodes.ASTORE, 3),
430-
Op(Opcodes.ICONST_1),
431-
Jump(Opcodes.GOTO, Label(17)),
432-
Label(10),
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),
433434
FrameEntry(1, List("java/lang/Object"), List()),
434435
TypeOp(Opcodes.NEW, "scala/MatchError"),
435436
Op(Opcodes.DUP),
436437
VarOp(Opcodes.ALOAD, 2),
437438
Invoke(Opcodes.INVOKESPECIAL, "scala/MatchError", "<init>", "(Ljava/lang/Object;)V", false),
438439
Op(Opcodes.ATHROW),
439-
Label(17),
440-
FrameEntry(0, List("Test", "java/lang/Object", "java/lang/Object", "Test"), List(1)),
441-
Op(Opcodes.IRETURN)
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)
442446
)
443447
assert(instructions == expected,
444448
"`test` was not properly generated\n" + diffInstructions(instructions, expected))

0 commit comments

Comments
 (0)