Test for missing dependencies of macro arguments

Add a test which shows the problem of not properly capturing dependencies
of macro arguments.
This commit is contained in:
Grzegorz Kossakowski 2014-02-07 22:52:44 +01:00 committed by Martin Duhem
parent 905028a6ae
commit 2a98355c64
6 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,5 @@
package macro
object Client {
Provider.printTree(Foo.str)
}

View File

@ -0,0 +1,5 @@
package macro
object Foo {
def str: String = "abc"
}

View File

@ -0,0 +1,3 @@
package macro
object Foo {
}

View File

@ -0,0 +1,12 @@
package macro
import scala.language.experimental.macros
import scala.reflect.macros._
object Provider {
def printTree(arg: Any) = macro printTreeImpl
def printTreeImpl(c: Context)(arg: c.Expr[Any]): c.Expr[String] = {
val argStr = arg.tree.toString
val literalStr = c.universe.Literal(c.universe.Constant(argStr))
c.Expr[String](literalStr)
}
}

View File

@ -0,0 +1,29 @@
import sbt._
import Keys._
object build extends Build {
val defaultSettings = Seq(
libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-reflect" % _ ),
incOptions := incOptions.value.withNameHashing(true)
)
lazy val root = Project(
base = file("."),
id = "macro",
aggregate = Seq(macroProvider, macroClient),
settings = Defaults.defaultSettings ++ defaultSettings
)
lazy val macroProvider = Project(
base = file("macro-provider"),
id = "macro-provider",
settings = Defaults.defaultSettings ++ defaultSettings
)
lazy val macroClient = Project(
base = file("macro-client"),
id = "macro-client",
dependencies = Seq(macroProvider),
settings = Defaults.defaultSettings ++ defaultSettings
)
}

View File

@ -0,0 +1,15 @@
> compile
# remove `Foo.str` which is an argument to a macro that incremental compiler doesn't see in
# Client.scala because macro has been already expanded
$ copy-file macro-client/changes/Foo.scala macro-client/Foo.scala
# we should recompile Foo.scala first and then fail to compile Client.scala due to missing
# `Foo.str`; however recompilation of Client.scala is never triggered due to missing
# dependency
-> macro-client/compile
> clean
-> compile