Fixes match error when using withDottyCompat

Fixes https://github.com/sbt/sbt/issues/6210

scodec-bits is published with pvp versionScheme (nice), this means that
we should just evaluate the version portion for pvp-ness, but I was
using `guessSecondSegment` that checks for Scala suffix. That's mistake
1.

`guessSecondSegment` assumes that the Scala suffix uses the given
ScalaModuleInfo, but with 2.13-3 sandwich we can't assume this.
In the reported case, Scala module is 3.0.0-M3 but scodec-bits uses
2.13. So that's mistake 2.

This attempts to correct both the mistakes.
1. Instead of `guessSecondSegment`, this adds a simpler `evalPvp`
function.
2. `guessSecondSegment` just looks for `_2.` or `_3` and ignores the
Scala module.
This commit is contained in:
Eugene Yokota 2020-12-19 17:08:24 -05:00
parent 6c1926603f
commit 2308d0a3a7
3 changed files with 36 additions and 5 deletions

View File

@ -98,12 +98,25 @@ object EvictionWarningOptions {
lazy val defaultGuess: Function1[(ModuleID, Option[ModuleID], Option[ScalaModuleInfo]), Boolean] =
guessSbtOne orElse guessSecondSegment orElse guessSemVer orElse guessFalse
private def isNameScalaSuffixed(name: String): Boolean =
name.contains("_2.") || name.contains("_3") || name.contains("_4")
/** A partial function that checks if given m2 is suffixed, and use pvp to evaluate. */
lazy val guessSecondSegment
: PartialFunction[(ModuleID, Option[ModuleID], Option[ScalaModuleInfo]), Boolean] = {
case (m1, Some(m2), Some(scalaModuleInfo))
if m2.name.endsWith("_" + scalaModuleInfo.scalaFullVersion) || m2.name.endsWith(
"_" + scalaModuleInfo.scalaBinaryVersion
) =>
case (m1, Some(m2), Some(_)) if isNameScalaSuffixed(m2.name) =>
(m1.revision, m2.revision) match {
case (VersionNumber(ns1, ts1, es1), VersionNumber(ns2, ts2, es2)) =>
VersionNumber.SecondSegment
.isCompatible(VersionNumber(ns1, ts1, es1), VersionNumber(ns2, ts2, es2))
case _ => false
}
}
/** A partial function that checks two versions match pvp. */
private[sbt] lazy val evalPvp
: PartialFunction[(ModuleID, Option[ModuleID], Option[ScalaModuleInfo]), Boolean] = {
case (m1, Some(m2), _) =>
(m1.revision, m2.revision) match {
case (VersionNumber(ns1, ts1, es1), VersionNumber(ns2, ts2, es2)) =>
VersionNumber.SecondSegment

View File

@ -283,6 +283,24 @@ object EvictionWarningSpec extends BaseIvySpecification {
)
}
test("Comparing 2.13 libraries with pvp under Scala 3.0.0-M3 should work") {
val m1 = "org.scodec" % "scodec-bits_2.13" % "1.1.21"
val m2 = "org.scodec" % "scodec-bits_2.13" % "1.1.22"
assert(
EvictionWarningOptions
.evalPvp((m1, Option(m2), Option(dummyScalaModuleInfo("3.0.0-M3"))))
)
}
test("Comparing 2.13 libraries with guessSecondSegment under Scala 3.0.0-M3 should work") {
val m1 = "org.scodec" % "scodec-bits_2.13" % "1.1.21"
val m2 = "org.scodec" % "scodec-bits_2.13" % "1.1.22"
assert(
EvictionWarningOptions
.guessSecondSegment((m1, Option(m2), Option(dummyScalaModuleInfo("3.0.0-M3"))))
)
}
def akkaActor214 =
ModuleID("com.typesafe.akka", "akka-actor", "2.1.4").withConfigurations(Some("compile")) cross CrossVersion.binary
def akkaActor230 =

View File

@ -1 +1 @@
sbt.version=1.4.2
sbt.version=1.4.5