Skip to content

Lifted inner method tries to use this #545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
smarter opened this issue May 7, 2015 · 2 comments
Closed

Lifted inner method tries to use this #545

smarter opened this issue May 7, 2015 · 2 comments
Assignees

Comments

@smarter
Copy link
Member

smarter commented May 7, 2015

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
@smarter smarter changed the title lifted inner method try to use this Lifted inner method tries to use this May 7, 2015
@DarkDimius
Copy link
Contributor

@smarter
The problem is in types. You should be able to see it if you enable
-print-types
Even though 'inner' is marked static,
it uses Ident with type TermRef(ThisType(Test), foo)

On 7 May 2015 21:23:09 Guillaume Martres [email protected] wrote:

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

Reply to this email directly or view it on GitHub:
#545

@DarkDimius
Copy link
Contributor

I'll fix this tomorrow.

@DarkDimius DarkDimius self-assigned this May 7, 2015
DarkDimius added a commit that referenced this issue May 13, 2015
Fix #545: no need to make members of static classes static.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants