From d986c452fa91037dda432b0b5d654b8c916be0d6 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 13 Jan 2021 16:53:17 +0100 Subject: [PATCH] Add beta-reduction regression test Fixes #9456 --- .../backend/jvm/InlineBytecodeTests.scala | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala b/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala index 0ee4d3641b85..829bc2607feb 100644 --- a/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala +++ b/compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala @@ -582,4 +582,37 @@ class InlineBytecodeTests extends DottyBytecodeTest { } } + + @Test def i9456 = { + val source = """class Foo { + | def test: Int = inline2(inline1(2.+)) + | + | inline def inline1(inline f: Int => Int): Int => Int = i => f(1) + | + | inline def inline2(inline f: Int => Int): Int = f(2) + 3 + |} + """.stripMargin + + checkBCode(source) { dir => + val clsIn = dir.lookupName("Foo.class", directory = false).input + val clsNode = loadClassNode(clsIn) + + val fun = getMethod(clsNode, "test") + val instructions = instructionsFromMethod(fun) + val expected = // TODO room for constant folding + List( + Op(ICONST_1), + VarOp(ISTORE, 1), + Op(ICONST_2), + VarOp(ILOAD, 1), + Op(IADD), + Op(ICONST_3), + Op(IADD), + Op(IRETURN), + ) + assert(instructions == expected, + "`f` was not properly inlined in `fun`\n" + diffInstructions(instructions, expected)) + + } + } }