Skip to content

Commit eb2f503

Browse files
authored
Merge pull request #11113 from dotty-staging/fix-#9456
Add beta-reduction regression test
2 parents 96413a5 + d986c45 commit eb2f503

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,4 +582,37 @@ class InlineBytecodeTests extends DottyBytecodeTest {
582582

583583
}
584584
}
585+
586+
@Test def i9456 = {
587+
val source = """class Foo {
588+
| def test: Int = inline2(inline1(2.+))
589+
|
590+
| inline def inline1(inline f: Int => Int): Int => Int = i => f(1)
591+
|
592+
| inline def inline2(inline f: Int => Int): Int = f(2) + 3
593+
|}
594+
""".stripMargin
595+
596+
checkBCode(source) { dir =>
597+
val clsIn = dir.lookupName("Foo.class", directory = false).input
598+
val clsNode = loadClassNode(clsIn)
599+
600+
val fun = getMethod(clsNode, "test")
601+
val instructions = instructionsFromMethod(fun)
602+
val expected = // TODO room for constant folding
603+
List(
604+
Op(ICONST_1),
605+
VarOp(ISTORE, 1),
606+
Op(ICONST_2),
607+
VarOp(ILOAD, 1),
608+
Op(IADD),
609+
Op(ICONST_3),
610+
Op(IADD),
611+
Op(IRETURN),
612+
)
613+
assert(instructions == expected,
614+
"`f` was not properly inlined in `fun`\n" + diffInstructions(instructions, expected))
615+
616+
}
617+
}
585618
}

0 commit comments

Comments
 (0)