Skip to content

Commit

Permalink
extract class dependency from 'classOf' Literal
Browse files Browse the repository at this point in the history
  • Loading branch information
natansil committed Mar 11, 2018
1 parent f2e77da commit ccd17b6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,25 @@ class DependencySpecification extends UnitSpec {
assert(inheritance("B") === Set.empty)
}

it should "extract class dependency from 'classOf' literal" in {
val srcA =
"""object A {
| print(classOf[B])
|}""".stripMargin
val srcB = "class B"

val compilerForTesting = new ScalaCompilerForUnitTesting
val classDependencies =
compilerForTesting.extractDependenciesFromSrcs(srcA, srcB)

val memberRef = classDependencies.memberRef
val inheritance = classDependencies.inheritance
assert(memberRef("A") === Set("B"))
assert(inheritance("A") === Set.empty)
assert(memberRef("B") === Set.empty)
assert(inheritance("B") === Set.empty)
}

it should "handle top level import dependencies" in {
val srcA =
"""
Expand Down
3 changes: 3 additions & 0 deletions internal/compiler-bridge/src/main/scala/xsbt/Dependency.scala
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with

traverseTrees(body)

case Literal(value) if value.tag == ClazzTag =>
addTypeDependencies(value.typeValue)

/* Original type trees have to be traversed because typer is very
* aggressive when expanding explicit user-defined types. For instance,
* `Foo#B` will be expanded to `C` and the dependency on `Foo` will be
Expand Down

0 comments on commit ccd17b6

Please sign in to comment.