diff --git a/core/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala b/core/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala index b09f42ca7..1f58cfe7d 100644 --- a/core/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala +++ b/core/src/main/scala/sbt/internal/librarymanagement/cross/CrossVersionUtil.scala @@ -92,12 +92,18 @@ object CrossVersionUtil { // // - For non-stable Scala 3 versions, compiler versions can read TASTy in an older stable format but their TASTY versions are not compatible between each other even if the compilers have the same minor version (https://docs.scala-lang.org/scala3/reference/language-versions/binary-compatibility.html) // - private[sbt] def isBinaryCompatibleWith(newVersion: String, origVersion: String): Boolean = { + private[sbt] def isScalaBinaryCompatibleWith(newVersion: String, origVersion: String): Boolean = { (newVersion, origVersion) match { - case (NonReleaseV_n("2", nMin, _, _), NonReleaseV_n("2", oMin, _, _)) => nMin == oMin - case (ReleaseV("3", nMin, _, _), ReleaseV("3", oMin, _, _)) => nMin.toInt >= oMin.toInt - case (NonReleaseV_1("3", nMin, _, _), ReleaseV("3", oMin, _, _)) => nMin.toInt > oMin.toInt - case _ => newVersion == origVersion + case (NonReleaseV_n("2", nMin, _, _), NonReleaseV_n("2", oMin, _, _)) => + nMin == oMin + case (ReleaseV(nMaj, nMin, _, _), ReleaseV(oMaj, oMin, _, _)) + if nMaj == oMaj && nMaj.toLong >= 3 => + nMin.toInt >= oMin.toInt + case (NonReleaseV_1(nMaj, nMin, _, _), ReleaseV(oMaj, oMin, _, _)) + if nMaj == oMaj && nMaj.toLong >= 3 => + nMin.toInt > oMin.toInt + case _ => + newVersion == origVersion } } diff --git a/core/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala b/core/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala index a60f30325..03cd97e88 100644 --- a/core/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala +++ b/core/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala @@ -239,6 +239,6 @@ private[librarymanagement] abstract class CrossVersionFunctions { /** * Returns `true` if a project targeting version `origVersion` can run with version `newVersion`. */ - def isBinaryCompatibleWith(newVersion: String, origVersion: String): Boolean = - CrossVersionUtil.isBinaryCompatibleWith(newVersion, origVersion) + def isScalaBinaryCompatibleWith(newVersion: String, origVersion: String): Boolean = + CrossVersionUtil.isScalaBinaryCompatibleWith(newVersion, origVersion) } diff --git a/core/src/test/scala/sbt/librarymanagement/CrossVersionTest.scala b/core/src/test/scala/sbt/librarymanagement/CrossVersionTest.scala index b4e570083..aae585b16 100644 --- a/core/src/test/scala/sbt/librarymanagement/CrossVersionTest.scala +++ b/core/src/test/scala/sbt/librarymanagement/CrossVersionTest.scala @@ -284,53 +284,53 @@ class CrossVersionTest extends UnitSpec { patchVersion("2.11.8-X1.5-bin-extra") shouldBe Some("artefact_2.11.8-X1.5") } - "isBinaryCompatibleWith" should "for (2.10.4, 2.10.5) return true" in { - isBinaryCompatibleWith("2.10.4", "2.10.5") shouldBe true + "isScalaBinaryCompatibleWith" should "for (2.10.4, 2.10.5) return true" in { + isScalaBinaryCompatibleWith("2.10.4", "2.10.5") shouldBe true } it should "for (2.10.6, 2.10.5) return true" in { - isBinaryCompatibleWith("2.10.6", "2.10.5") shouldBe true + isScalaBinaryCompatibleWith("2.10.6", "2.10.5") shouldBe true } it should "for (2.11.0, 2.10.5) return false" in { - isBinaryCompatibleWith("2.11.0", "2.10.5") shouldBe false + isScalaBinaryCompatibleWith("2.11.0", "2.10.5") shouldBe false } it should "for (3.0.0, 2.10.5) return false" in { - isBinaryCompatibleWith("3.0.0", "2.10.5") shouldBe false + isScalaBinaryCompatibleWith("3.0.0", "2.10.5") shouldBe false } it should "for (3.0.0, 3.1.0) return false" in { - isBinaryCompatibleWith("3.0.0", "3.1.0") shouldBe false + isScalaBinaryCompatibleWith("3.0.0", "3.1.0") shouldBe false } it should "for (3.1.0, 3.0.0) return true" in { - isBinaryCompatibleWith("3.1.0", "3.0.0") shouldBe true + isScalaBinaryCompatibleWith("3.1.0", "3.0.0") shouldBe true } it should "for (3.1.0, 3.1.1) return true" in { - isBinaryCompatibleWith("3.1.0", "3.1.1") shouldBe true + isScalaBinaryCompatibleWith("3.1.0", "3.1.1") shouldBe true } it should "for (3.1.1, 3.1.0) return true" in { - isBinaryCompatibleWith("3.1.1", "3.1.0") shouldBe true + isScalaBinaryCompatibleWith("3.1.1", "3.1.0") shouldBe true } it should "for (2.10.0-M1, 2.10.5) return true" in { - isBinaryCompatibleWith("2.10.0-M1", "2.10.5") shouldBe true + isScalaBinaryCompatibleWith("2.10.0-M1", "2.10.5") shouldBe true } it should "for (2.10.5, 2.10.0-M1) return true" in { - isBinaryCompatibleWith("2.10.5", "2.10.0-M1") shouldBe true + isScalaBinaryCompatibleWith("2.10.5", "2.10.0-M1") shouldBe true } it should "for (2.10.0-M1, 2.10.0-M2) return true" in { - isBinaryCompatibleWith("2.10.0-M1", "2.10.0-M2") shouldBe true + isScalaBinaryCompatibleWith("2.10.0-M1", "2.10.0-M2") shouldBe true } it should "for (2.10.0-M1, 2.11.0-M1) return false" in { - isBinaryCompatibleWith("2.10.0-M1", "2.11.0-M1") shouldBe false + isScalaBinaryCompatibleWith("2.10.0-M1", "2.11.0-M1") shouldBe false } it should "for (3.1.0-M1, 3.0.0) return true" in { - isBinaryCompatibleWith("3.1.0-M1", "3.0.0") shouldBe true + isScalaBinaryCompatibleWith("3.1.0-M1", "3.0.0") shouldBe true } it should "for (3.1.0-M1, 3.1.0) return false" in { - isBinaryCompatibleWith("3.1.0-M1", "3.1.0") shouldBe false + isScalaBinaryCompatibleWith("3.1.0-M1", "3.1.0") shouldBe false } it should "for (3.1.0-M1, 3.1.0-M2) return false" in { - isBinaryCompatibleWith("3.1.0-M1", "3.1.0-M2") shouldBe false + isScalaBinaryCompatibleWith("3.1.0-M1", "3.1.0-M2") shouldBe false } it should "for (3.1.0-M2, 3.1.0-M1) return false" in { - isBinaryCompatibleWith("3.1.0-M2", "3.1.0-M1") shouldBe false + isScalaBinaryCompatibleWith("3.1.0-M2", "3.1.0-M1") shouldBe false } private def constantVersion(value: String) =