Skip to content
This repository
Browse code

SI-6039 Harden against irrelevant filesystem details

The symbol loader need not create and populate package
symbols merely because there is a directory somewhere.
Every package created based on the existence of a directory
should contain a classfile, either directly or indirectly.
  • Loading branch information...
commit b0758f5cb9d966b940933d48bdbb45d17a80de66 1 parent 9a2f6c7
Paul Phillips paulp authored
8 src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
@@ -234,10 +234,14 @@ abstract class SymbolLoaders {
234 234 }
235 235 }
236 236 if (!root.isEmptyPackageClass) {
  237 + // Only enter packages which contain a class or a non-empty package
237 238 for (pkg <- classpath.packages) {
238   - enterPackage(root, pkg.name, new PackageLoader(pkg))
  239 + if (pkg.isEmptyOfClassfiles) {
  240 + log(s"Discarding $root/$pkg as it contains no classfiles.")
  241 + }
  242 + else
  243 + enterPackage(root, pkg.name, new PackageLoader(pkg))
239 244 }
240   -
241 245 openPackageModule(root)
242 246 }
243 247 }
2  src/compiler/scala/tools/nsc/util/ClassPath.scala
@@ -211,6 +211,8 @@ abstract class ClassPath[T] {
211 211 def validPackage(name: String) = (name != "META-INF") && (name != "") && (name.charAt(0) != '.')
212 212 def validSourceFile(name: String) = endsScala(name) || endsJava(name)
213 213
  214 + def isEmptyOfClassfiles: Boolean = classes.isEmpty && packages.forall(_.isEmptyOfClassfiles)
  215 +
214 216 /**
215 217 * Find a ClassRep given a class name of the form "package.subpackage.ClassName".
216 218 * Does not support nested classes on .NET
18 test/files/run/t6039.scala
... ... @@ -0,0 +1,18 @@
  1 +import scala.tools.partest._
  2 +
  3 +object Test extends StoreReporterDirectTest {
  4 + private def compileCode(): Boolean = {
  5 + new java.io.File("util") mkdirs
  6 + val classpath = List(sys.props("partest.lib"), ".") mkString sys.props("path.separator")
  7 + log(s"classpath = $classpath")
  8 + compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(packageCode)
  9 + }
  10 + def code = ???
  11 + def packageCode = """
  12 +package scala.bippy
  13 +class A { new util.Random() }
  14 +"""
  15 + def show(): Unit = {
  16 + assert(compileCode(), filteredInfos take 1 mkString "")
  17 + }
  18 +}

0 comments on commit b0758f5

Please sign in to comment.
Something went wrong with that request. Please try again.