Skip to content

Commit 578b334

Browse files
committed
Add bytecode test
1 parent 904fed2 commit 578b334

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

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

+28
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package dotty.tools.backend.jvm
33
import org.junit.Assert._
44
import org.junit.Test
55

6+
import scala.tools.asm.Opcodes
7+
68
class TestBCode extends DottyBytecodeTest {
79
import ASMConverters._
810
@Test def nullChecks = {
@@ -213,4 +215,30 @@ class TestBCode extends DottyBytecodeTest {
213215
assert(!arrayWrapped, "Arrays should not be wrapped when passed to a Java varargs method\n")
214216
}
215217
}
218+
219+
@Test def efficientTryCases = {
220+
val source =
221+
"""
222+
|class Test {
223+
| def test =
224+
| try print("foo")
225+
| catch {
226+
| case _: scala.runtime.NonLocalReturnControl[_] => ()
227+
| }
228+
|}
229+
""".stripMargin
230+
231+
checkBCode(source) { dir =>
232+
val moduleIn = dir.lookupName("Test.class", directory = false)
233+
val moduleNode = loadClassNode(moduleIn.input)
234+
val method = getMethod(moduleNode, "test")
235+
236+
val hasInstanceof = instructionsFromMethod(method).exists {
237+
case TypeOp(Opcodes.INSTANCEOF, _) => true
238+
case _ => false
239+
}
240+
241+
assert(!hasInstanceof, "Try case should not issue INSTANCEOF opcode\n")
242+
}
243+
}
216244
}

tests/pos/i746.scala

-10
This file was deleted.

0 commit comments

Comments
 (0)