File tree 2 files changed +30
-0
lines changed
src/dotty/tools/dotc/transform
test/dotty/tools/backend/jvm
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 {
76
76
(pre == NoPrefix || pre.widen.typeSymbol.isStatic) && // Does not require outer class check
77
77
! tp.symbol.is(Flags .Trait ) && // Traits not supported by JVM
78
78
tp.derivesFrom(defn.ThrowableClass )
79
+ case tp : AppliedType =>
80
+ isSimpleThrowable(tp.tycon)
79
81
case _ =>
80
82
false
81
83
}
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ package dotty.tools.backend.jvm
3
3
import org .junit .Assert ._
4
4
import org .junit .Test
5
5
6
+ import scala .tools .asm .Opcodes
7
+
6
8
class TestBCode extends DottyBytecodeTest {
7
9
import ASMConverters ._
8
10
@ Test def nullChecks = {
@@ -213,4 +215,30 @@ class TestBCode extends DottyBytecodeTest {
213
215
assert(! arrayWrapped, " Arrays should not be wrapped when passed to a Java varargs method\n " )
214
216
}
215
217
}
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
+ }
216
244
}
You can’t perform that action at this time.
0 commit comments