Skip to content

Commit e13cd9f

Browse files
committed
Add ByteCode test for partial functions
1 parent 1eeb9f0 commit e13cd9f

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
@@ -264,4 +264,27 @@ class TestBCode extends DottyBytecodeTest {
264264
}
265265
}
266266
}
267+
268+
@Test def partialFunctions = {
269+
val source =
270+
"""object Foo {
271+
| def magic(x: Int) = x
272+
| val foo: PartialFunction[Int, Int] = { case x => magic(x) }
273+
|}
274+
""".stripMargin
275+
276+
checkBCode(source) { dir =>
277+
// We test that the anonymous class generated for the partial function
278+
// holds the method implementations and does not use forwarders
279+
val clsIn = dir.lookupName("Foo$$anon$1.class", directory = false).input
280+
val clsNode = loadClassNode(clsIn)
281+
val applyOrElse = getMethod(clsNode, "applyOrElse")
282+
val instructions = instructionsFromMethod(applyOrElse)
283+
val callMagic = instructions.exists {
284+
case Invoke(_, _, "magic", _, _) => true
285+
case _ => false
286+
}
287+
assertTrue(callMagic)
288+
}
289+
}
267290
}

0 commit comments

Comments
 (0)