Fix isScalaBinaryCompatibleWith

Problem
-------
Current impl is relaxed about comparing non-release Scala 2.x versions.

Solutution
----------
Use scalaApiVersion to compare two Scala 2 versions.
This commit is contained in:
Eugene Yokota 2022-06-26 21:05:52 -04:00
parent eb62b4f65d
commit 457af6978f
2 changed files with 10 additions and 8 deletions

View File

@ -94,8 +94,10 @@ object CrossVersionUtil {
//
private[sbt] def isScalaBinaryCompatibleWith(newVersion: String, origVersion: String): Boolean = {
(newVersion, origVersion) match {
case (NonReleaseV_n("2", nMin, _, _), NonReleaseV_n("2", oMin, _, _)) =>
nMin == oMin
case (NonReleaseV_n("2", _, _, _), NonReleaseV_n("2", _, _, _)) =>
val api1 = scalaApiVersion(newVersion)
val api2 = scalaApiVersion(origVersion)
(api1.isDefined && api1 == api2) || (newVersion == origVersion)
case (ReleaseV(nMaj, nMin, _, _), ReleaseV(oMaj, oMin, _, _))
if nMaj == oMaj && nMaj.toLong >= 3 =>
nMin.toInt >= oMin.toInt

View File

@ -308,14 +308,14 @@ class CrossVersionTest extends UnitSpec {
it should "for (3.1.1, 3.1.0) return true" in {
isScalaBinaryCompatibleWith("3.1.1", "3.1.0") shouldBe true
}
it should "for (2.10.0-M1, 2.10.5) return true" in {
isScalaBinaryCompatibleWith("2.10.0-M1", "2.10.5") shouldBe true
it should "for (2.10.0-M1, 2.10.5) return false" in {
isScalaBinaryCompatibleWith("2.10.0-M1", "2.10.5") shouldBe false
}
it should "for (2.10.5, 2.10.0-M1) return true" in {
isScalaBinaryCompatibleWith("2.10.5", "2.10.0-M1") shouldBe true
it should "for (2.10.5, 2.10.0-M1) return false" in {
isScalaBinaryCompatibleWith("2.10.5", "2.10.0-M1") shouldBe false
}
it should "for (2.10.0-M1, 2.10.0-M2) return true" in {
isScalaBinaryCompatibleWith("2.10.0-M1", "2.10.0-M2") shouldBe true
it should "for (2.10.0-M1, 2.10.0-M2) return false" in {
isScalaBinaryCompatibleWith("2.10.0-M1", "2.10.0-M2") shouldBe false
}
it should "for (2.10.0-M1, 2.11.0-M1) return false" in {
isScalaBinaryCompatibleWith("2.10.0-M1", "2.11.0-M1") shouldBe false