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

Inconsistent root package name #9728

Closed
scabug opened this issue Mar 31, 2016 · 3 comments
Closed

Inconsistent root package name #9728

scabug opened this issue Mar 31, 2016 · 3 comments
Assignees

Comments

@scabug
Copy link

scabug commented Mar 31, 2016

Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_77).
Type in expressions for evaluation. Or try :help.

scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._

scala> import scala.reflect.runtime.currentMirror
import scala.reflect.runtime.currentMirror

scala> currentMirror.moduleSymbol(None.getClass).owner.owner.name
res0: reflect.runtime.universe.Symbol#NameType = <root>

scala> termNames.ROOTPKG
res1: reflect.runtime.universe.termNames.NameType = _root_

scala> currentMirror.moduleSymbol(None.getClass).owner.owner.name == termNames.ROOTPKG
res2: Boolean = false
@scabug
Copy link
Author

scabug commented Mar 31, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9728?orig=1
Reporter: @Atry
Affected Versions: 2.11.8

@scabug
Copy link
Author

scabug commented Apr 3, 2016

@retronym said:

scala> currentMirror.RootPackage
res12: reflect.runtime.universe.ModuleSymbol = package _root_

scala> currentMirror.RootClass
res13: reflect.runtime.universe.ClassSymbol = package <root>

scala> currentMirror.RootClass.asClass.module
res14: reflect.runtime.universe.Symbol = package _root_

This is certainly confusing, but I don't think it is a bug. When you navigate .owner.owner, you get to the package class of the root package, not the root package itself. The package class is named TypeName("<root>"), whereas the root package is named TermName("_root_"). The term is the only one of these name that is designed to be referenced from user code, so it used underscores rather than <..>.

@scabug scabug closed this as completed Apr 3, 2016
@scabug
Copy link
Author

scabug commented Apr 3, 2016

@Atry said (edited on Apr 3, 2016 5:31:43 PM UTC):
I found that there is a ROOT constant and Symbol.isRoot method in scala-compiler, however there is not such a constant or method in scala-reflect. How could a macro writer determine if a TermName is root without internal APIs?

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

2 participants