Merge pull request #1754 from Duhemm/fix-1655

Check for null type trees in dependency extraction
This commit is contained in:
Josh Suereth 2014-12-04 17:57:44 -05:00
commit 488a62c8bf
5 changed files with 84 additions and 1 deletions

View File

@ -139,7 +139,9 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile {
*/
case ident: Ident =>
addDependency(ident.symbol)
case typeTree: TypeTree =>
// In some cases (eg. macro annotations), `typeTree.tpe` may be null.
// See sbt/sbt#1593 and sbt/sbt#1655.
case typeTree: TypeTree if typeTree.tpe != null =>
val typeSymbolCollector = new CollectTypeTraverser({
case tpe if !tpe.typeSymbol.isPackage => tpe.typeSymbol
})

View File

@ -0,0 +1,6 @@
@hello
case class Test(x: Int)
object Main extends App {
Test(3).hello
}

View File

@ -0,0 +1,26 @@
import scala.reflect.macros.whitebox.Context
import scala.language.experimental.macros
import scala.annotation.StaticAnnotation
object HelloMacro {
def impl(c: Context)(annottees: c.Tree*): c.Tree = {
import c.universe._
annottees match {
case (classDecl: ClassDef) :: Nil =>
val q"$mods class $name[..$tparams] $ctorMods(...$paramss) extends { ..$earlydefns } with ..$bases { $self => ..$body }" = classDecl
q"""
case class $name(...$paramss) extends ..$bases {
..$body
def hello = "Hello"
}
"""
case _ => c.abort(c.enclosingPosition, "Invalid annottee")
}
}
}
class hello extends StaticAnnotation {
def macroTransform(annottees: Any*): Any = macro HelloMacro.impl
}

View File

@ -0,0 +1,45 @@
import sbt._
import Keys._
object BuildSettings {
val paradiseVersion = "2.0.1"
val buildSettings = Defaults.defaultSettings ++ Seq(
version := "1.0.0",
scalacOptions ++= Seq(""),
scalaVersion := "2.11.4",
resolvers += Resolver.sonatypeRepo("snapshots"),
resolvers += Resolver.sonatypeRepo("releases"),
addCompilerPlugin("org.scalamacros" % "paradise" % paradiseVersion cross CrossVersion.full),
incOptions := incOptions.value.withNameHashing(true)
)
}
object MyBuild extends Build {
import BuildSettings._
lazy val root: Project = Project(
"root",
file("."),
settings = buildSettings ++ Seq(
run <<= run in Compile in core
)
) aggregate(macros, core)
lazy val macros: Project = Project(
"macros",
file("macros"),
settings = buildSettings ++ Seq(
libraryDependencies <+= (scalaVersion)("org.scala-lang" % "scala-reflect" % _),
libraryDependencies ++= (
if (scalaVersion.value.startsWith("2.10")) List("org.scalamacros" %% "quasiquotes" % paradiseVersion)
else Nil
)
)
)
lazy val core: Project = Project(
"core",
file("core"),
settings = buildSettings
) dependsOn(macros)
}

View File

@ -0,0 +1,4 @@
# The goal of this test is just to make sure that sbt does
# not crash when it encounters a macro annotation
# See #1655 and #1593
> compile