Skip to content

When nested functions are inlined, boxing variables should be avoided #4522

Closed
@Glavo

Description

@Glavo

For this code:

object C {
  def fun: Int = {
    var a = 10
    inline def f(arg: => Unit) = {
      a += 1
      arg
    }

    f {
      return a
    }
    a
  }
}

The decompiled code looks like this:

public final class C$ {
    public static final C$ MODULE$;

    static {
        new C$();
    }

    public C$() {
        MODULE$ = this;
    }

    public int fun() {
        IntRef a = IntRef.create(10);
        int var2 = a.elem + 1;
        a.elem = var2;
        return a.elem;
    }

    private void f$1(IntRef a$1, Function0 arg) {
        int var3 = a$1.elem + 1;
        a$1.elem = var3;
        arg.apply();
    }
}

a should not be boxed

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions