Skip to content

Don't warn on private proxy extension idiom #24066

@som-snytt

Description

@som-snytt

Compiler version

3.8

Minimized code

class Foo(val someField: Int)

extension (foo: Foo)
  def someField = foo.someField // warns even if private
  def bar1 = 1 + someField
  def bar2 = 2 + someField
  def bar3 = 3 + someField

#17543 (comment)

Output

5 |  private def someField = foo.someField
  |              ^
  |Extension method someField will never be selected from type Foo
  |because Foo already has a member with the same name and compatible parameter types.

Expectation

The someField extension is a trick to turn the references in barN to foo.someField, which as per the definition of the someField extension is the desired result.

Possibly, leveraging the trick should be permitted without warning if the extension is @unused or if the rhs is a forwarding expression.

Metadata

Metadata

Assignees

Labels

area:lintingLinting warnings enabled with -W or -Xlintbetter-errorsIssues concerned with improving confusing/unhelpful diagnostic messagesitype:bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions