mirror of https://github.com/sbt/sbt.git
Merge branch 'pr/4084' into wip/bumpzinc
This commit is contained in:
commit
a629dea053
|
|
@ -2885,9 +2885,14 @@ object Classpaths {
|
||||||
excl: FileFilter): Classpath =
|
excl: FileFilter): Classpath =
|
||||||
(base * (filter -- excl) +++ (base / config.name).descendantsExcept(filter, excl)).classpath
|
(base * (filter -- excl) +++ (base / config.name).descendantsExcept(filter, excl)).classpath
|
||||||
|
|
||||||
def autoPlugins(report: UpdateReport, internalPluginClasspath: Seq[File]): Seq[String] = {
|
|
||||||
|
@deprecated("The method only works for Scala 2, use the overloaded version to support both Scala 2 and Scala 3", "1.1.5")
|
||||||
|
def autoPlugins(report: UpdateReport, internalPluginClasspath: Seq[File]): Seq[String] =
|
||||||
|
autoPlugins(report, internalPluginClasspath, isDotty = false)
|
||||||
|
|
||||||
|
def autoPlugins(report: UpdateReport, internalPluginClasspath: Seq[File], isDotty: Boolean): Seq[String] = {
|
||||||
val pluginClasspath = report.matching(configurationFilter(CompilerPlugin.name)) ++ internalPluginClasspath
|
val pluginClasspath = report.matching(configurationFilter(CompilerPlugin.name)) ++ internalPluginClasspath
|
||||||
val plugins = sbt.internal.inc.classpath.ClasspathUtilities.compilerPlugins(pluginClasspath)
|
val plugins = sbt.internal.inc.classpath.ClasspathUtilities.compilerPlugins(pluginClasspath, isDotty)
|
||||||
plugins.map("-Xplugin:" + _.getAbsolutePath).toSeq
|
plugins.map("-Xplugin:" + _.getAbsolutePath).toSeq
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2907,7 +2912,7 @@ object Classpaths {
|
||||||
lazy val compilerPluginConfig = Seq(
|
lazy val compilerPluginConfig = Seq(
|
||||||
scalacOptions := {
|
scalacOptions := {
|
||||||
val options = scalacOptions.value
|
val options = scalacOptions.value
|
||||||
val newPlugins = autoPlugins(update.value, internalCompilerPluginClasspath.value.files)
|
val newPlugins = autoPlugins(update.value, internalCompilerPluginClasspath.value.files, ScalaInstance.isDotty(scalaVersion.value))
|
||||||
val existing = options.toSet
|
val existing = options.toSet
|
||||||
if (autoCompilerPlugins.value) options ++ newPlugins.filterNot(existing) else options
|
if (autoCompilerPlugins.value) options ++ newPlugins.filterNot(existing) else options
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
[@liufengyun]: https://github.com/liufengyun
|
||||||
|
|
||||||
|
[4073]: https://github.com/sbt/sbt/issues/4073
|
||||||
|
[4084]: https://github.com/sbt/sbt/pull/4084
|
||||||
|
|
||||||
|
|
||||||
|
### Improvements
|
||||||
|
|
||||||
|
- Detect dotty plugins which have descriptor file named `plugin.properties` instead of `scalac-plugin.xml`. [#4073][4073]/[#4084][4084] by [@liufengyun][@liufengyun]
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
lazy val dottyVersion = dottyLatestNightlyBuild
|
||||||
|
|
||||||
|
lazy val pluginSetting = Seq(
|
||||||
|
name := "dividezero",
|
||||||
|
version := "0.0.1",
|
||||||
|
organization := "ch.epfl.lamp",
|
||||||
|
scalaVersion := dottyVersion,
|
||||||
|
|
||||||
|
libraryDependencies ++= Seq(
|
||||||
|
"ch.epfl.lamp" %% "dotty" % "provided"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
lazy val plugin = (project in file("plugin")).settings(pluginSetting: _*)
|
||||||
|
|
||||||
|
lazy val app = (project in file(".")).settings(
|
||||||
|
scalaVersion := dottyVersion,
|
||||||
|
libraryDependencies += compilerPlugin("ch.epfl.lamp" %% "dividezero" % "0.0.1")
|
||||||
|
)
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
package dividezero
|
||||||
|
|
||||||
|
import dotty.tools.dotc._
|
||||||
|
import core._
|
||||||
|
import Contexts.Context
|
||||||
|
import plugins._
|
||||||
|
import Phases.Phase
|
||||||
|
import ast.tpd
|
||||||
|
import transform.MegaPhase.MiniPhase
|
||||||
|
import Decorators._
|
||||||
|
import Symbols.Symbol
|
||||||
|
import Constants.Constant
|
||||||
|
import transform.{LinkAll, Pickler}
|
||||||
|
|
||||||
|
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.phaseName)
|
||||||
|
override val runsBefore = Set(LinkAll.phaseName)
|
||||||
|
|
||||||
|
override 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 == "/"
|
||||||
|
|
||||||
|
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)
|
||||||
|
tpd.Literal(Constant(0))
|
||||||
|
case _ =>
|
||||||
|
tree
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
pluginClass=dividezero.DivideZero
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.2.0")
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
package hello
|
||||||
|
object Hello {
|
||||||
|
def main(args: Array[String]): Unit = {
|
||||||
|
val dotty: Int | String = "dotty"
|
||||||
|
|
||||||
|
val y = 5 / 0 // error
|
||||||
|
100 + 6 / 0 // error
|
||||||
|
6L / 0L // error
|
||||||
|
val z = 7 / 0.0 // error
|
||||||
|
|
||||||
|
println(s"Hello $dotty!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
> plugin/publishLocal
|
||||||
|
> app/run
|
||||||
Loading…
Reference in New Issue