Skip to content
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

Cannot create renamed copies of members of this using export #9704

Closed
neko-kai opened this issue Sep 1, 2020 · 2 comments
Closed

Cannot create renamed copies of members of this using export #9704

neko-kai opened this issue Sep 1, 2020 · 2 comments

Comments

@neko-kai
Copy link
Contributor

neko-kai commented Sep 1, 2020

Minimized code

abstract class WordSpec {
  export this.{extension_in => extension_should}
  
  extension(s: String) def in(f: => Any): Unit = {
    println(s)
    f
  }
}

object test extends WordSpec {  
  "X" should {
    "add numbers" in {
     assert(1 + 1 == 2)
    }
  }
}

Output

no eligible member extension_in at this
this.extension_in cannot be exported because it is already a member of class AnyWordSpec
  export this.{extension_in => extension_should}

Expectation

Seems like the check for duplicates is over-eager and happens before renames are taken into account, making it illegal to rename symbols in this, but legal otherwise. Workaround is to create a proxy object and re-export from it:

abstract class WordSpec {
  export inner.{extension_in => extension_should}
  export inner.extension_in
  
  object inner {
    extension(s: String) def in(f: => Any): Unit = {
      println(s)
      f
    }
  }
}
bishabosha added a commit to dotty-staging/dotty that referenced this issue Oct 30, 2020
@odersky
Copy link
Contributor

odersky commented Dec 27, 2020

The behavior corresponds to what the spec says:

A member is eligible if all of the following holds:

  • its owner is not a base class of the class(*) containing the export clause, ...

If we want to change this we'd need a feature request, and a discussion in depth. I personally think that a change would not be simple at all. There would be many things to specify, what constutes a clash and what doesn't.

@odersky odersky closed this as completed Dec 27, 2020
@som-snytt
Copy link
Contributor

Existing feature request at lampepfl/dotty-feature-requests#148

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

3 participants