Skip to content

Lifted inner method tries to use this #545

Closed
@smarter

Description

@smarter

In this example, inner is miscompiled but inner2 works fine:

object Test {
  def foo() = {}

  def outer() = {
    def inner() = {
      foo()
    }
  }

  def outer2() = {
    def inner2() = {
      Test.foo()
    }
  }

  def main(args: Array[String]): Unit = {}
}

Even though the output of -Xprint:genBCode does not show any difference:

package <empty> {
  final lazy module val Test: Test$ = new Test$()
  final module class Test$ extends Object { this: <notype> => 
    def <init>(): Test$ = {
      super()
      ()
    }
    def foo(): Unit = ()
    def outer(): Unit = ()
    def outer2(): Unit = ()
    def main(args: String[]): Unit = ()
    private <static> def inner$1(): Unit = Test.foo()
    private <static> def inner2$1(): Unit = Test.foo()
  }
}

javap reveals the error:

  private static void inner$1();
    Code:
       0: aload_0
       1: invokevirtual #26                 // Method foo:()V
       4: return

  private static void inner2$1();
    Code:
       0: getstatic     #15                 // Field MODULE$:LTest$;
       3: invokevirtual #26                 // Method foo:()V
       6: return

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions