File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
src/dotty/tools/dotc/transform
test/dotty/tools/backend/jvm Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,8 @@ class TryCatchPatterns extends MiniPhase {
7676 (pre == NoPrefix || pre.widen.typeSymbol.isStatic) && // Does not require outer class check
7777 ! tp.symbol.is(Flags .Trait ) && // Traits not supported by JVM
7878 tp.derivesFrom(defn.ThrowableClass )
79+ case tp : AppliedType =>
80+ isSimpleThrowable(tp.tycon)
7981 case _ =>
8082 false
8183 }
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ package dotty.tools.backend.jvm
33import org .junit .Assert ._
44import org .junit .Test
55
6+ import scala .tools .asm .Opcodes
7+
68class 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}
You can’t perform that action at this time.
0 commit comments