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.
This commit is contained in:
Lukas Rytz 2024-01-12 21:16:31 +01:00
parent 35bc07bd9e
commit 4c74358707
1 changed files with 17 additions and 0 deletions

View File

@ -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)