diff --git a/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/src/main/scala/hello/Hello.scala b/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/app/src/main/scala/hello/Hello.scala similarity index 99% rename from sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/src/main/scala/hello/Hello.scala rename to sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/app/src/main/scala/hello/Hello.scala index 99ae2d0d7..d92d9bb84 100644 --- a/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/src/main/scala/hello/Hello.scala +++ b/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/app/src/main/scala/hello/Hello.scala @@ -1,4 +1,5 @@ package hello + object Hello { def main(args: Array[String]): Unit = { val dotty: Int | String = "dotty" diff --git a/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/appOK/src/main/scala/hello/Hello.scala b/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/appOK/src/main/scala/hello/Hello.scala new file mode 100644 index 000000000..c67735762 --- /dev/null +++ b/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/appOK/src/main/scala/hello/Hello.scala @@ -0,0 +1,8 @@ +package hello + +object Hello { + def main(args: Array[String]): Unit = { + val dotty: Int | String = "dotty" + println(s"Hello $dotty!") + } +} diff --git a/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/build.sbt b/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/build.sbt index 124a017c3..b666df990 100644 --- a/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/build.sbt +++ b/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/build.sbt @@ -1,15 +1,30 @@ -lazy val dottyVersion = "0.11.0-RC1" +lazy val dottyVersion = "0.14.0-RC1" -ThisBuild / scalaVersion := dottyVersion -ThisBuild / organization := "com.example" - -lazy val plugin = (project in file("plugin")) +lazy val plugin = project + .in(file("plugin")) .settings( name := "dividezero", - version := "0.0.1" + version := "0.0.1", + organization := "ch.epfl.lamp", + scalaVersion := dottyVersion, + + scalacOptions ++= Seq( + "-language:implicitConversions" + ), + + libraryDependencies ++= Seq( + "ch.epfl.lamp" %% "dotty-compiler" % scalaVersion.value % "provided" + ) ) -lazy val app = (project in file(".")) +lazy val app = project + .in(file("app")) .settings( - libraryDependencies += compilerPlugin("com.example" %% "dividezero" % "0.0.1"), + scalaVersion := dottyVersion + ) + +lazy val appOk = project + .in(file("appOk")) + .settings( + scalaVersion := dottyVersion ) diff --git a/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/changes/build.sbt b/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/changes/build.sbt new file mode 100644 index 000000000..c14f87559 --- /dev/null +++ b/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/changes/build.sbt @@ -0,0 +1,28 @@ +lazy val dottyVersion = "0.14.0-RC1" + +lazy val plugin = project + .in(file("plugin")) + .settings( + name := "dividezero", + version := "0.0.1", + organization := "ch.epfl.lamp", + scalaVersion := dottyVersion, + + libraryDependencies ++= Seq( + "ch.epfl.lamp" %% "dotty" % scalaVersion.value % "provided" + ) + ) + +lazy val app = project + .in(file("app")) + .settings( + scalaVersion := dottyVersion, + addCompilerPlugin("ch.epfl.lamp" %% "dividezero" % "0.0.1") + ) + +lazy val appOk = project + .in(file("appOk")) + .settings( + scalaVersion := dottyVersion, + addCompilerPlugin("ch.epfl.lamp" %% "dividezero" % "0.0.1") + ) diff --git a/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/pending b/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/pending deleted file mode 100644 index 28c06d4d6..000000000 --- a/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/pending +++ /dev/null @@ -1,2 +0,0 @@ -> plugin/publishLocal -> app/run diff --git a/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/plugin/DivideZero.scala b/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/plugin/DivideZero.scala index c110a7cee..feadac221 100644 --- a/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/plugin/DivideZero.scala +++ b/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/plugin/DivideZero.scala @@ -10,31 +10,32 @@ import transform.MegaPhase.MiniPhase import Decorators._ import Symbols.Symbol import Constants.Constant -import transform.{LinkAll, Pickler} +import transform.{Pickler, Staging} +/** Compiler plugin that emits an error when compiling a division by zero */ class DivideZero extends PluginPhase with StandardPlugin { val name: String = "divideZero" override val description: String = "divide zero check" val phaseName = name - override val runsAfter = Set(Pickler.name) - override val runsBefore = Set(LinkAll.name) + override val runsAfter = Set(Staging.name) + override val runsBefore = Set(Pickler.name) - override def init(options: List[String]): List[PluginPhase] = this :: Nil + def init(options: List[String]): List[PluginPhase] = this :: Nil private def isNumericDivide(sym: Symbol)(implicit ctx: Context): Boolean = { def test(tpe: String): Boolean = - (sym.owner eq ctx.requiredClass(tpe.toTermName)) && sym.name.show == "/" + (sym.owner eq ctx.requiredClass(tpe)) && sym.name.show == "/" test("scala.Int") || test("scala.Long") || test("scala.Short") || test("scala.Float") || test("scala.Double") } override def transformApply(tree: tpd.Apply)(implicit ctx: Context): tpd.Tree = tree match { case tpd.Apply(fun, tpd.Literal(Constants.Constant(v)) :: Nil) if isNumericDivide(fun.symbol) && v == 0 => - ctx.warning("divide by zero", tree.pos) + ctx.error("divide by zero", tree.sourcePos) tpd.Literal(Constant(0)) case _ => tree } -} +} \ No newline at end of file diff --git a/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/plugin/src/main/resources/plugin.properties b/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/plugin/src/main/resources/plugin.properties index db215842c..f903a0f32 100644 --- a/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/plugin/src/main/resources/plugin.properties +++ b/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/plugin/src/main/resources/plugin.properties @@ -1 +1 @@ -pluginClass=dividezero.DivideZero \ No newline at end of file +pluginClass=dividezero.DivideZero diff --git a/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/project/plugins.sbt b/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/project/plugins.sbt index 174dbbcb8..61407ff6b 100644 --- a/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/project/plugins.sbt +++ b/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/project/plugins.sbt @@ -1 +1 @@ -addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.2.6") +addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.3.1") diff --git a/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/test b/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/test new file mode 100644 index 000000000..35d9f1be8 --- /dev/null +++ b/sbt/src/sbt-test/compiler-project/dotty-compiler-plugin/test @@ -0,0 +1,17 @@ +# Should compile OK without the plugin +> app/compile + +# Publish plugin locally +> plugin/publishLocal + +# Enable plugin +$ copy-file changes/build.sbt build.sbt +> reload + +# Should compile with the plugin +> clean +> appOk/compile + +# Should NOT compile with the plugin +> clean +-> app/compile