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
_root_ should always refer to the root package #6217
Comments
Imported From: https://issues.scala-lang.org/browse/SI-6217?orig=1 |
@paulp said:
|
@adriaanm said: |
@paulp said: package p {
package _root_ {
package scala {
sealed trait Option[+T] { def isEmpty = false ; def donkey = 5 }
final case class None[T]() extends Option[T] { def get: T = null.asInstanceOf[T] }
final case class Some[T](x: T) extends Option[T] { }
}
}
}
// Meanwhile, in some other file
package p {
object Test {
import _root_.scala.Option
def f[T](x: Option[T]) = x.donkey
}
} There is no "donkey" method on root .scala.Option. If root is to behave like any other relative package, then there is quite literally no reason for it to exist. And conversely, this does NOT compile, but certainly SHOULD. root.scala.Option does have a "get" method. package p {
object Test2 {
import _root_.scala.Option
def f[T](x: Option[T]) = x.get
// ./a.scala:18: error: value get is not a member of p._root_.scala.Option[T]
// def f[T](x: Option[T]) = x.get
// ^
// one error found
}
} |
@adriaanm said (edited on Feb 19, 2014 6:54:52 AM UTC): |
@adriaanm said (edited on Feb 20, 2014 5:33:06 AM UTC): |
@adriaanm said: |
@paulp said: |
@dwijnand said: I wonder what you think: one could argue that you must know what you're doing if you're defining you're own |
@paulp said: If packages had been defined up front to be relative to an abstract root, and there were some facility for controlling where that root is, that could be useful - albeit impractical on the jvm, which doesn't offer any way to virtualize packages short of bytecode rewriting. But the whole reason people use _root_ is they want to know what they're getting. It's explicitly NOT a virtual path. It's in the specifiction: "The special predefined name _root_ refers to the outermost root package which contains all top-level packages." |
@jvican has taken an interest in this recently |
Yes. Making |
The PR just enforces that Hopefully this averts enshrining |
Is there any reason that a package should ever be named |
personally I would prefer the denotation of the root package not to be a legal character sequence for a package, and more obvious to the eye, e.g.
but that is probably not achievable any more |
@mkeskells In case you missed this https://contributors.scala-lang.org/t/proposed-syntax-for-root/1035 |
This PR would be the minimally useful warning only, in lieu of possible future syntaxes. Disallowing @mkeskells your example is already illegal:
I haven't excavated the why, although |
@jvican I didn't know about that - looks good I wonder what havoc Instead lets make the root, in whatever form not a legal identifier! |
To summarize the compromise, |
I see no reason this should be allowed to happen, and a lot of reasons it shouldn't.
So to be clear, that source should not compile, but it should not compile because root should be a reserved word. The whole point of root is to know what you are importing. Tying this into another ticket I opened recently:
The text was updated successfully, but these errors were encountered: