Skip to content

inline def with inline function parameter not inlining the function #9456

Closed
@rcano

Description

@rcano

Minimized code

object inlinetest:
  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

Output

Disassemblied (via CFR) output of test

    public int test() {
        return BoxesRunTime.unboxToInt((Object)((JFunction1.mcII.sp & Serializable)(JFunction1.mcII.sp & Serializable)i -> {
            int x = 1;
            return 2 + x;
        }).apply((Object)BoxesRunTime.boxToInteger((int)2))) + 3;
    }

Expectation

The result should not contain any lambda.

Notes

Manually inlining inline1 produces the intended result

 def test: Int =
    inline2(i => 2 + 1)

it gets properly inlined

    public int test() {
        return 6;
    }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions