Skip to content

Commit

Permalink
Record used name for packages
Browse files Browse the repository at this point in the history
  • Loading branch information
allanrenucci committed Apr 18, 2018
1 parent 33da2b6 commit 6f3cd28
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,12 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
val fromClass = resolveDependencySource
if (fromClass.exists) { // can happen when visiting imports
assert(fromClass.isClass)
_dependencies += ClassDependency(fromClass, enclOrModuleClass, DependencyByMemberRef)

addUsedName(fromClass, mangledName(sym), UseScope.Default)
// packages have class symbol. Only record them as used names but bot dependency
if (!sym.is(Package)) {
_dependencies += ClassDependency(fromClass, enclOrModuleClass, DependencyByMemberRef)
}
}
}

Expand All @@ -315,7 +319,6 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT
!sym.exists ||
sym.unforcedIsAbsent || // ignore dependencies that have a symbol but do not exist.
// e.g. java.lang.Object companion object
sym.is(Package) ||
sym.isEffectiveRoot ||
sym.isAnonymousFunction ||
sym.isAnonymousClass
Expand Down
7 changes: 4 additions & 3 deletions sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ExtractUsedNamesSpecification {
|}""".stripMargin
val compilerForTesting = new ScalaCompilerForUnitTesting
val usedNames = compilerForTesting.extractUsedNamesFromSrc(src)
val expectedNames = standardNames ++ Set("A", "A2")
val expectedNames = standardNames ++ Set("a", "A", "A2", "b")
// names used at top level are attributed to the first class defined in a compilation unit

assertEquals(expectedNames, usedNames("a.A"))
Expand Down Expand Up @@ -43,7 +43,7 @@ class ExtractUsedNamesSpecification {
|}""".stripMargin
val compilerForTesting = new ScalaCompilerForUnitTesting
val usedNames = compilerForTesting.extractUsedNamesFromSrc(srcA, srcB)
val expectedNames = standardNames ++ Set("A", "B", "C", "D", "BB")
val expectedNames = standardNames ++ Set("a", "c", "A", "B", "C", "D", "b", "BB")
assertEquals(expectedNames, usedNames("b.X"))
}

Expand Down Expand Up @@ -286,7 +286,8 @@ class ExtractUsedNamesSpecification {
val compilerForTesting = new ScalaCompilerForUnitTesting
val usedNames = compilerForTesting.extractUsedNamesFromSrc(src)

assertEquals(standardNames + "List", usedNames("Test"))
val expectedNames = standardNames ++ Set("java", "util", "List")
assertEquals(expectedNames, usedNames("Test"))
}

/**
Expand Down

0 comments on commit 6f3cd28

Please sign in to comment.