Skip to content

Commit 545dd69

Browse files
committed
Add bytecode test to verify absence of Tuple2.apply calls
1 parent 568b115 commit 545dd69

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ trait DottyBytecodeTest {
133133
}, l.stringLines)
134134
}
135135

136+
def assertNoInvoke(m: MethodNode, receiver: String, method: String): Unit =
137+
assertNoInvoke(instructionsFromMethod(m), receiver, method)
138+
def assertNoInvoke(l: List[Instruction], receiver: String, method: String): Unit = {
139+
assert(!l.exists {
140+
case Invoke(_, `receiver`, `method`, _, _) => true
141+
case _ => false
142+
}, s"Found unexpected invoke of $receiver.$method in:\n${l.stringLines}")
143+
}
144+
136145
def diffInstructions(isa: List[Instruction], isb: List[Instruction]): String = {
137146
val len = Math.max(isa.length, isb.length)
138147
val sb = new StringBuilder

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,21 @@ class DottyBytecodeTests extends DottyBytecodeTest {
16061606
}
16071607
}
16081608

1609+
@Test
1610+
def simpleTupleExtraction(): Unit = {
1611+
val code =
1612+
"""class C {
1613+
| def f1(t: (Int, String)) =
1614+
| val (i, s) = t
1615+
| i + s.length
1616+
|}
1617+
""".stripMargin
1618+
checkBCode(code) { dir =>
1619+
val c = loadClassNode(dir.lookupName("C.class", directory = false).input)
1620+
assertNoInvoke(getMethod(c, "f1"), "scala/Tuple2$", "apply") // no Tuple2.apply call
1621+
}
1622+
}
1623+
16091624
@Test
16101625
def deprecation(): Unit = {
16111626
val code =

0 commit comments

Comments
 (0)