Skip to content

Extension method is ignored when non-accessible member of same name is present #7375

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
TomPoczos opened this issue Oct 6, 2019 · 1 comment · Fixed by #10859
Closed

Comments

@TomPoczos
Copy link

TomPoczos commented Oct 6, 2019

minimized code

trait Entity[M, T, P]
  
  def (me: M) receive(sender: T)(msg: P)(given Entity[T, M, P]): Unit
  
  def (me: M) name(): String

class GreetingPerson(private val name: String)

object GreetingPerson

  given GreetingPersonEntity: Entity[GreetingPerson, GreetedPerson, String]

    def (me: GreetingPerson) receive(sender: GreetedPerson)(msg: String)(given Entity[GreetedPerson, GreetingPerson, String]): Unit = 
       println(f"Thanks for saying $msg, ${sender.name()}")
 
    def (me: GreetingPerson) name() =
      me.name

class GreetedPerson(private val name: String)

object GreetedPerson

  given GreetedPersonEntity: Entity[GreetedPerson, GreetingPerson, String]

    def (me: GreetedPerson) receive(sender: GreetingPerson)(msg: String)(given Entity[GreetingPerson, GreetedPerson, String]): Unit = 
      println(f"Thanks for saying $msg, ${sender.name()}")
      

    def (me: GreetedPerson) name() = 
      me.name

expectation

The code should compile but it doesn't unless val name is renamed to something else.

@OlivierBlanvillain
Copy link
Contributor

Minimized:

class Foo(private val name: String) // Compiles with s/name/blah/

object Bar {
  def (f: Foo) name() = ""

  def main(f: Foo) =
    println(s"Hello ${f.name()}")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants