Skip to content

Commit 081c97a

Browse files
committed
Add ByteCode test for partial functions
1 parent 58234f3 commit 081c97a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,27 @@ class TestBCode extends DottyBytecodeTest {
287287
assertTrue(containsExpectedCall)
288288
}
289289
}
290+
291+
@Test def partialFunctions = {
292+
val source =
293+
"""object Foo {
294+
| def magic(x: Int) = x
295+
| val foo: PartialFunction[Int, Int] = { case x => magic(x) }
296+
|}
297+
""".stripMargin
298+
299+
checkBCode(source) { dir =>
300+
// We test that the anonymous class generated for the partial function
301+
// holds the method implementations and does not use forwarders
302+
val clsIn = dir.lookupName("Foo$$anon$1.class", directory = false).input
303+
val clsNode = loadClassNode(clsIn)
304+
val applyOrElse = getMethod(clsNode, "applyOrElse")
305+
val instructions = instructionsFromMethod(applyOrElse)
306+
val callMagic = instructions.exists {
307+
case Invoke(_, _, "magic", _, _) => true
308+
case _ => false
309+
}
310+
assertTrue(callMagic)
311+
}
312+
}
290313
}

0 commit comments

Comments
 (0)