mirror of https://github.com/sbt/sbt.git
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:
parent
15b4befa9c
commit
19658c2ee0
|
|
@ -1,4 +1,5 @@
|
|||
package hello
|
||||
|
||||
object Hello {
|
||||
def main(args: Array[String]): Unit = {
|
||||
val dotty: Int | String = "dotty"
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package hello
|
||||
|
||||
object Hello {
|
||||
def main(args: Array[String]): Unit = {
|
||||
val dotty: Int | String = "dotty"
|
||||
println(s"Hello $dotty!")
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
)
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
> plugin/publishLocal
|
||||
> app/run
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +1 @@
|
|||
pluginClass=dividezero.DivideZero
|
||||
pluginClass=dividezero.DivideZero
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.2.6")
|
||||
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.3.1")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Reference in New Issue