Skip to content

Commit 824ae13

Browse files
authored
Merge pull request #5 from djspiewak/feature/2.13
(Hopefully) fixed 2.13 handling with the flag removal in M4
2 parents f0149bd + a370b6c commit 824ae13

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

src/main/scala/PartialUnification.scala

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,45 @@ object PartialUnification extends AutoPlugin {
1313

1414
import autoImport._
1515

16-
def pluginOrFlag(scalaVersion: String, pluginModule: ModuleID): Either[ModuleID, String] = {
17-
val pluginDependency = Left(compilerPlugin(pluginModule cross CrossVersion.full))
18-
val flag = Right("-Ypartial-unification")
19-
val VersionNumber((major +: minor +: patch +: _), _, _) = scalaVersion
20-
21-
(major, minor, patch) match {
22-
case (2, 10, p) if p >= 6 => pluginDependency
23-
case (2, 11, 8) => pluginDependency
24-
case (2, 11, p) if p >= 9 => flag
25-
case (2, 12, _) => flag
26-
case (2, 13, _) => flag
16+
def pluginOrFlag(scalaVersion: String, pluginModule: ModuleID): Resolution = {
17+
val pluginDependency = Resolution.Plugin(compilerPlugin(pluginModule cross CrossVersion.full))
18+
val flag = Resolution.Flag("-Ypartial-unification")
19+
val VersionNumber((major +: minor +: patch +: _), tags, _) = scalaVersion
20+
21+
(major, minor, patch, tags) match {
22+
case (2, 10, p, _) if p >= 6 => pluginDependency
23+
case (2, 11, 8, _) => pluginDependency
24+
case (2, 11, p, _) if p >= 9 => flag
25+
case (2, 12, _, _) => flag
26+
case (2, 13, _, milestone +: _) if milestone == "M1" || milestone == "M2" || milestone == "M3" => flag // ignoring the M4 snapshot
27+
case (2, 13, _, _) => Resolution.NothingHappens
2728
case _ => sys.error(s"scala version $scalaVersion is not supported by this plugin.")
2829
}
2930
}
3031

3132
override val projectSettings = Seq(
3233
partialUnificationModule := "com.milessabin" % "si2712fix-plugin" % "1.2.0",
33-
libraryDependencies ++= pluginOrFlag(scalaVersion.value, partialUnificationModule.value).left.toSeq,
34-
scalacOptions ++= pluginOrFlag(scalaVersion.value, partialUnificationModule.value).right.toSeq
34+
35+
libraryDependencies ++= {
36+
pluginOrFlag(scalaVersion.value, partialUnificationModule.value) match {
37+
case Resolution.Plugin(id) => Seq(id)
38+
case _ => Seq.empty
39+
}
40+
},
41+
42+
scalacOptions ++= {
43+
pluginOrFlag(scalaVersion.value, partialUnificationModule.value) match {
44+
case Resolution.Flag(flag) => Seq(flag)
45+
case _ => Seq.empty
46+
}
47+
}
3548
)
49+
50+
sealed trait Resolution extends Product with Serializable
51+
52+
object Resolution {
53+
final case class Plugin(id: ModuleID) extends Resolution
54+
final case class Flag(flag: String) extends Resolution
55+
case object NothingHappens extends Resolution
56+
}
3657
}

0 commit comments

Comments
 (0)