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

Closed
@smarter

Description

@smarter

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
  }

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