Reenable dotty-compiler-plugin test

https://github.com/lampepfl/dotty/issues/5671 is fixed now.

Also synchronize the test with
8ffed083c7/sbt-dotty/sbt-test/sbt-dotty/compiler-plugin
This commit is contained in:
Guillaume Martres 2019-04-30 22:05:49 +02:00
parent 15b4befa9c
commit 19658c2ee0
9 changed files with 87 additions and 19 deletions

View File

@ -1,4 +1,5 @@
package hello
object Hello {
def main(args: Array[String]): Unit = {
val dotty: Int | String = "dotty"

View File

@ -0,0 +1,8 @@
package hello
object Hello {
def main(args: Array[String]): Unit = {
val dotty: Int | String = "dotty"
println(s"Hello $dotty!")
}
}

View File

@ -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
)

View File

@ -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")
)

View File

@ -1,2 +0,0 @@
> plugin/publishLocal
> app/run

View File

@ -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
}
}
}

View File

@ -1 +1 @@
pluginClass=dividezero.DivideZero
pluginClass=dividezero.DivideZero

View File

@ -1 +1 @@
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.2.6")
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.3.1")

View File

@ -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