diff --git a/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala b/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala index 62955dcb72a7..593801633f76 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala @@ -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 not dependency + if (!sym.is(Package)) { + _dependencies += ClassDependency(fromClass, enclOrModuleClass, DependencyByMemberRef) + } } } @@ -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(PackageClass) || sym.isEffectiveRoot || sym.isAnonymousFunction || sym.isAnonymousClass diff --git a/sbt-bridge/test/xsbt/DependencySpecification.scala b/sbt-bridge/test/xsbt/DependencySpecification.scala index d702c5993be3..12dd3113a7ac 100644 --- a/sbt-bridge/test/xsbt/DependencySpecification.scala +++ b/sbt-bridge/test/xsbt/DependencySpecification.scala @@ -145,6 +145,25 @@ class DependencySpecification { assertEquals(Set("abc.A"), deps("H")) } + @Test + def extractedClassDependenciesOnPackageObject = { + val srcA = "package object foo { def bar = 1 }" + val srcB = + """|package foo + | + |class Test { + | bar + |} + """.stripMargin + + val compilerForTesting = new ScalaCompilerForUnitTesting + val classDependencies = + compilerForTesting.extractDependenciesFromSrcs(srcA, srcB) + + val memberRef = classDependencies.memberRef + assertEquals(Set("foo.package"), memberRef("foo.Test")) + } + private def extractClassDependenciesPublic: ExtractedClassDependencies = { val srcA = "class A" val srcB = "class B extends D[A]" diff --git a/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala b/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala index 1c05fd3b6394..befe2dd433d3 100644 --- a/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala +++ b/sbt-bridge/test/xsbt/ExtractUsedNamesSpecification.scala @@ -275,6 +275,21 @@ class ExtractUsedNamesSpecification { assertEquals(Set(), findPatMatUsages(notUsedInPatternMatch)) } + @Test + def extractedNamesInImport = { + val src = + """|import java.util.List + | + |class Test + """.stripMargin + + val compilerForTesting = new ScalaCompilerForUnitTesting + val usedNames = compilerForTesting.extractUsedNamesFromSrc(src) + + val expectedNames = standardNames ++ Set("java", "util", "List") + assertEquals(expectedNames, usedNames("Test")) + } + /** * Standard names that appear in every compilation unit that has any class * definition. diff --git a/sbt-dotty/sbt-test/source-dependencies/package-object-implicit/Test.scala b/sbt-dotty/sbt-test/source-dependencies/package-object-implicit/Test.scala new file mode 100644 index 000000000000..2ae5c84d1eb3 --- /dev/null +++ b/sbt-dotty/sbt-test/source-dependencies/package-object-implicit/Test.scala @@ -0,0 +1,6 @@ +package foo + +object Test { + def test(implicit x: Int = 1): String = x.toString + def main(args: Array[String]): Unit = test +} diff --git a/sbt-dotty/sbt-test/source-dependencies/package-object-implicit/changes/package.scala b/sbt-dotty/sbt-test/source-dependencies/package-object-implicit/changes/package.scala new file mode 100644 index 000000000000..774fa9a700a7 --- /dev/null +++ b/sbt-dotty/sbt-test/source-dependencies/package-object-implicit/changes/package.scala @@ -0,0 +1,3 @@ +package object foo { + implicit val x: Int = ??? +} diff --git a/sbt-dotty/sbt-test/source-dependencies/package-object-implicit/pending b/sbt-dotty/sbt-test/source-dependencies/package-object-implicit/pending new file mode 100644 index 000000000000..7c063eaea347 --- /dev/null +++ b/sbt-dotty/sbt-test/source-dependencies/package-object-implicit/pending @@ -0,0 +1,7 @@ +> run + +$ copy-file changes/package.scala package.scala + +# New implicit in scope from package object that makes run throws +# clean run fails correctly +-> run diff --git a/sbt-dotty/sbt-test/source-dependencies/package-object-implicit/project/DottyInjectedPlugin.scala b/sbt-dotty/sbt-test/source-dependencies/package-object-implicit/project/DottyInjectedPlugin.scala new file mode 100644 index 000000000000..ce3d46d79921 --- /dev/null +++ b/sbt-dotty/sbt-test/source-dependencies/package-object-implicit/project/DottyInjectedPlugin.scala @@ -0,0 +1,12 @@ +import sbt._ +import Keys._ + +object DottyInjectedPlugin extends AutoPlugin { + override def requires = plugins.JvmPlugin + override def trigger = allRequirements + + override val projectSettings = Seq( + scalaVersion := sys.props("plugin.scalaVersion"), + scalacOptions += "-language:Scala2" + ) +} diff --git a/sbt-dotty/sbt-test/source-dependencies/package-object-implicit/project/plugins.sbt b/sbt-dotty/sbt-test/source-dependencies/package-object-implicit/project/plugins.sbt new file mode 100644 index 000000000000..c17caab2d98c --- /dev/null +++ b/sbt-dotty/sbt-test/source-dependencies/package-object-implicit/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % sys.props("plugin.version"))