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

Top level packages can't be aliased in import declaration #9125

Closed
scabug opened this issue Jan 30, 2015 · 7 comments · Fixed by scala/scala#9482
Closed

Top level packages can't be aliased in import declaration #9125

scabug opened this issue Jan 30, 2015 · 7 comments · Fixed by scala/scala#9482
Assignees
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) has PR help wanted parser
Milestone

Comments

@scabug
Copy link

scabug commented Jan 30, 2015

scala> import _root_.{scala => xxx}
<console>:7: error: _root_ cannot be imported
       import _root_.{scala => xxx}
              ^

It doesn't work in both the REPL and the IDE.

@scabug
Copy link
Author

scabug commented Jan 30, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9125?orig=1
Reporter: @sschaef
Affected Versions: 2.10.5

@SethTisue SethTisue changed the title _root_.scala can't be aliased in import declaration Top level packages can't be aliased in import declaration Feb 3, 2021
@SethTisue
Copy link
Member

was reported again at #12329 — I've changed the issue title to reflect that all top level packages are affected, not just the scala package

@SethTisue SethTisue added parser fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) help wanted labels Feb 3, 2021
@SethTisue SethTisue added this to the Backlog milestone Feb 3, 2021
@som-snytt
Copy link

Relatedly createdly scala/scala3#11296

@Jasper-M
Copy link

Jasper-M commented Feb 3, 2021

This was once disabled as part of the fix for #283. For any interested archaeologists.

@som-snytt
Copy link

Thanks, I did dig that up yesterday. It was right before the winter holidays, 2007. Probably there was not a lot of discussion about imposing the limitation as a stop-gap.

@Jasper-M
Copy link

Jasper-M commented Feb 3, 2021

Maybe back then import aliasing didn't exist yet? In that case it would make sense to disallow import _root_.foo.

@som-snytt
Copy link

Relatedly, my linked ticket was due to my own partial understanding. You want an import to shadow an enclosing package name. Using mutable would be an actual use case, but here is scala, showing that root import is useful without rename.

package example {
  package scala {
    object X {
      import _root_.scala
      def empty = scala.collection.mutable.ListBuffer.empty[Int]
    }
  }
}

Recently I was toying in this area because of the question whether it's possible to shadow scala in an enclosing package, for purposes of cross-compilation. (That only works if you don't want to write scala.Int and other things.) It wasn't obvious to me that writing package scala.collection here also shadows scala.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) has PR help wanted parser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants