Fix for dependency on class file corresponding to a package. (#620)

While trying to determine binary dependencies sbt lookups class files
corresponding to symbols. It tried to do that for packages and most of the
time would fail because packages don't have corresponding class file
generated. However, in case of case insensitive file system, combined
with special nesting structure you could get spurious dependency.
See added test case for an example of such structure.

The remedy is to never even try to locate class files corresponding to
packages.

Fixes #620.
This commit is contained in:
Grzegorz Kossakowski 2012-11-27 00:14:04 -08:00 committed by Mark Harrah
parent 482b59be5d
commit 4c1c31e190
5 changed files with 24 additions and 0 deletions

View File

@ -81,6 +81,9 @@ final class Analyzer(val global: CallbackGlobal) extends Compat
private[this] final val classSeparator = '.'
private[this] def classFile(sym: Symbol): Option[(AbstractFile, String, Boolean)] =
// package can never have a corresponding class file; this test does not
// catch package objects (that do not have this flag set)
if (sym hasFlag scala.tools.nsc.symtab.Flags.PACKAGE) None else
{
import scala.tools.nsc.symtab.Flags
val name = flatname(sym, classSeparator) + moduleSuffix(sym)

View File

@ -0,0 +1,6 @@
TaskKey[Unit]("verify-binary-deps") <<= (compile in Compile, classDirectory in Compile, baseDirectory) map {
(a: sbt.inc.Analysis, classDir: java.io.File, base: java.io.File) =>
val nestedPkgClass = classDir / "test/nested.class"
val fooSrc = base / "src/main/scala/test/nested/Foo.scala"
assert(!a.relations.binaryDeps(fooSrc).contains(nestedPkgClass), a.relations.toString)
}

View File

@ -0,0 +1,3 @@
package test
trait Nested

View File

@ -0,0 +1,5 @@
package test.nested
trait Foo {
def xyz(x: test.Nested)
}

View File

@ -0,0 +1,7 @@
# Tests for bug when sbt would introduce dependency on non-existing
# class files corresponding to packages
> compile
# verifies that there's no dependency on a class file corresponding
# to a package
> verify-binary-deps