Skip to content

Commit

Permalink
Fix #127: Use unexpanded name instead of name
Browse files Browse the repository at this point in the history
It looks like scalac encodes access rights of objects in their names. To
make sure that we get the right simple names, we need to use
`unexpandedName` instead of `name` which will decipher these access
rights and return their simple names insted (with all the previous `$$`
prefixes stripped out).
  • Loading branch information
jvican committed Oct 13, 2017
1 parent 03e4119 commit adb54bc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
8 changes: 6 additions & 2 deletions internal/compiler-bridge/src/main/scala/xsbt/ClassName.scala
Expand Up @@ -68,15 +68,19 @@ trait ClassName extends Compat {
*
* If `s` represents a package object `pkg3`, then the returned name will be `pkg1.pkg2.pkg3.package`.
* If `s` represents a class `Foo` nested in package object `pkg3` then the returned name is `pkg1.pkg2.pk3.Foo`.
*
* Note that some objects with special access rights are encoded in names
* (like qualified privates `private[qualifier]`). In order to get the right
* original names, we need to use `unexpandedName`.
*/
protected def classNameAsSeenIn(in: Symbol, s: Symbol): String =
enteringPhase(currentRun.picklerPhase.next) {
if (in.isRoot || in.isRootPackage || in == NoSymbol || in.isEffectiveRoot)
s.simpleName.toString
else if (in.isPackageObjectOrClass)
in.owner.fullName + "." + s.name
in.owner.fullName + "." + s.unexpandedName
else
in.fullName + "." + s.name
in.fullName + "." + s.unexpandedName
}

private def pickledName(s: Symbol): Name =
Expand Down
3 changes: 0 additions & 3 deletions zinc/src/sbt-test/source-dependencies/issue-127/Foo.scala

This file was deleted.

1 change: 0 additions & 1 deletion zinc/src/sbt-test/source-dependencies/issue-127/pending

This file was deleted.

21 changes: 21 additions & 0 deletions zinc/src/sbt-test/source-dependencies/unexpanded-names/Foo.scala
@@ -0,0 +1,21 @@
// Foo.owner.isEffectiveRoot == true
class Fooo {
// This one is problematic because of expanded names
private[Fooo] object Bar
}

package issue127 {
// Foo.owner.isEffectiveRoot == false
class Foo {
private[Foo] object Bar
class Baz {
private[Baz] object Bazz
}
}

object Foo {
private[issue127] class Bippy
// This one is problematic because of expanded names
private[issue127] object Bippy
}
}
2 changes: 2 additions & 0 deletions zinc/src/sbt-test/source-dependencies/unexpanded-names/test
@@ -0,0 +1,2 @@
# See https://github.com/sbt/zinc/issues/127
> compile

0 comments on commit adb54bc

Please sign in to comment.