Skip to content

When a private member is accessed from an inline method, a new public accessor is created for every use of the private member #4322

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 Apr 13, 2018 · 0 comments

Comments

@smarter
Copy link
Member

smarter commented Apr 13, 2018

This code should only create one accessor for x, but it ends up creating three:

object Foo {
  private[this] val x: Int = 1

  inline def foo: Int = x + x + x
}
  final lazy module val Foo: Foo$ = new Foo$()
  final module class Foo$() extends Object() { this: Foo.type => 
    private[this] val x: Int = 1
    @Foo.foo$_inlineAccessor_$1.+(Foo.foo$_inlineAccessor_$2).+(
      Foo.foo$_inlineAccessor_$3
    ) inline def foo: Int = 
      Foo.foo$_inlineAccessor_$1.+(Foo.foo$_inlineAccessor_$2).+(
        Foo.foo$_inlineAccessor_$3
      )
    def foo$_inlineAccessor_$1: Int = Foo.x
    def foo$_inlineAccessor_$2: Int = Foo.x
    def foo$_inlineAccessor_$3: Int = Foo.x
  }
odersky added a commit to dotty-staging/dotty that referenced this issue May 5, 2018
odersky added a commit to dotty-staging/dotty that referenced this issue May 7, 2018
odersky added a commit that referenced this issue May 23, 2018
Fix #4322: Avoid generating multiple inline accessors for the same ac…
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

1 participant