diff --git a/sbt/src/sbt-test/source-dependencies/macro-annotation/core/src/main/scala/Test.scala b/sbt/src/sbt-test/source-dependencies/macro-annotation/core/src/main/scala/Test.scala new file mode 100644 index 000000000..4593483e8 --- /dev/null +++ b/sbt/src/sbt-test/source-dependencies/macro-annotation/core/src/main/scala/Test.scala @@ -0,0 +1,6 @@ +@hello +case class Test(x: Int) + +object Main extends App { + Test(3).hello +} \ No newline at end of file diff --git a/sbt/src/sbt-test/source-dependencies/macro-annotation/macros/src/main/scala/Macros.scala b/sbt/src/sbt-test/source-dependencies/macro-annotation/macros/src/main/scala/Macros.scala new file mode 100644 index 000000000..672c3d268 --- /dev/null +++ b/sbt/src/sbt-test/source-dependencies/macro-annotation/macros/src/main/scala/Macros.scala @@ -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 +} \ No newline at end of file diff --git a/sbt/src/sbt-test/source-dependencies/macro-annotation/project/Build.scala b/sbt/src/sbt-test/source-dependencies/macro-annotation/project/Build.scala new file mode 100644 index 000000000..a39f05bd5 --- /dev/null +++ b/sbt/src/sbt-test/source-dependencies/macro-annotation/project/Build.scala @@ -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) +} \ No newline at end of file diff --git a/sbt/src/sbt-test/source-dependencies/macro-annotation/test b/sbt/src/sbt-test/source-dependencies/macro-annotation/test new file mode 100644 index 000000000..a462c2a8b --- /dev/null +++ b/sbt/src/sbt-test/source-dependencies/macro-annotation/test @@ -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