From 4c74358707477d105bf8d4d4452e2b7971b73ba7 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Fri, 12 Jan 2024 21:16:31 +0100 Subject: [PATCH] Fail the build if 2.13 scalaVersion < scala artifact on classpath When expanding a macro compiled against a new Scala library, the runtime classpath of the compiler should not contain an older library. Otherwise a NoSuchMethodException can occur. A similar issue is present when running the Scala repl through sbt. An input line compiled against a new library could fail to run if the repl's runtime classpath is on an old version. --- main/src/main/scala/sbt/Defaults.scala | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index 00aae7174..c9b00f748 100644 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -1150,6 +1150,23 @@ object Defaults extends BuildCommon { .configuration(Configurations.ScalaTool) .getOrElse(sys.error(noToolConfiguration(managedScalaInstance.value))) + if (Classpaths.isScala213(sv)) { + for { + compileReport <- fullReport.configuration(Configurations.Compile) + libName <- ScalaArtifacts.Artifacts + } { + for (lib <- compileReport.modules.find(_.module.name == libName)) { + val libVer = lib.module.revision + if (VersionNumber(sv).matchesSemVer(SemanticSelector(s"<$libVer"))) + sys.error( + s"""`${name.value}/scalaVersion` needs to be upgraded to $libVer. To support backwards-only + |binary compatibility (SIP-51), the Scala compiler cannot be older than $libName on the + |dependency classpath. See `${name.value}/evicted` why $libName was upgraded from $sv to $libVer. + |""".stripMargin + ) + } + } + } def file(id: String): File = { val files = for { m <- toolReport.modules if m.module.name.startsWith(id)