mirror of https://github.com/sbt/sbt.git
Enable sbt-test/plugins/dotty-compiler-plugin
This commit is contained in:
parent
e13186fd22
commit
4310528ede
|
|
@ -1,4 +1,4 @@
|
|||
ThisBuild / scalaVersion := "3.1.3"
|
||||
ThisBuild / scalaVersion := "3.3.7"
|
||||
|
||||
lazy val plugin = project
|
||||
.in(file("plugin"))
|
||||
|
|
@ -18,12 +18,6 @@ lazy val plugin = project
|
|||
|
||||
lazy val app = project
|
||||
.in(file("app"))
|
||||
.settings(
|
||||
scalaVersion := dottyVersion
|
||||
)
|
||||
|
||||
lazy val appOk = project
|
||||
.in(file("appOk"))
|
||||
.settings(
|
||||
scalaVersion := dottyVersion
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
lazy val dottyVersion = "3.1.3"
|
||||
lazy val dottyVersion = "3.3.7"
|
||||
|
||||
lazy val plugin = project
|
||||
.in(file("plugin"))
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import transform.MegaPhase.MiniPhase
|
|||
import Decorators._
|
||||
import Symbols.Symbol
|
||||
import Constants.Constant
|
||||
import transform.{Pickler, Staging}
|
||||
import typer.TyperPhase
|
||||
|
||||
/** Compiler plugin that emits an error when compiling a division by zero */
|
||||
class DivideZero extends PluginPhase with StandardPlugin {
|
||||
|
|
@ -19,21 +19,20 @@ class DivideZero extends PluginPhase with StandardPlugin {
|
|||
|
||||
val phaseName = name
|
||||
|
||||
override val runsAfter = Set(Staging.name)
|
||||
override val runsBefore = Set(Pickler.name)
|
||||
override val runsAfter = Set(TyperPhase.name)
|
||||
|
||||
def init(options: List[String]): List[PluginPhase] = this :: Nil
|
||||
|
||||
private def isNumericDivide(sym: Symbol)(implicit ctx: Context): Boolean = {
|
||||
private def isNumericDivide(sym: Symbol)(using Context): Boolean = {
|
||||
def test(tpe: String): Boolean =
|
||||
(sym.owner eq ctx.requiredClass(tpe)) && sym.name.show == "/"
|
||||
(sym.owner eq Symbols.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 {
|
||||
override def transformApply(tree: tpd.Apply)(using Context): tpd.Tree = tree match {
|
||||
case tpd.Apply(fun, tpd.Literal(Constants.Constant(v)) :: Nil) if isNumericDivide(fun.symbol) && v == 0 =>
|
||||
ctx.error("divide by zero", tree.sourcePos)
|
||||
report.error("divide by zero", tree.sourcePos)
|
||||
tpd.Literal(Constant(0))
|
||||
case _ =>
|
||||
tree
|
||||
|
|
|
|||
Loading…
Reference in New Issue