Skip to content

Commit 052aea8

Browse files
authored
Make sure tasty-lib doesn't warn about Scala 3 Next (#2775)
1 parent 008c32f commit 052aea8

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

build.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ trait TastyLib extends ScalaCliCrossSbtModule
11631163
|
11641164
|/** Build-time constants. Generated by mill. */
11651165
|object Constants {
1166-
| def latestSupportedScala = "${Scala.defaultInternal}"
1166+
| def latestSupportedScala = "${Scala.defaultUser}"
11671167
|}
11681168
|""".stripMargin
11691169
if (!os.isFile(dest) || os.read(dest) != code)

modules/integration/src/test/scala/scala/cli/integration/CompileTestDefinitions.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,4 +697,15 @@ abstract class CompileTestDefinitions
697697
expect(out.contains("Too small maximum heap"))
698698
}
699699
}
700+
701+
test(s"TASTY processor does not warn about Scala $actualScalaVersion") {
702+
TestInputs(os.rel / "simple.sc" -> s"""println("Hello")""")
703+
.fromRoot { root =>
704+
val result =
705+
os.proc(TestUtil.cli, "compile", ".", extraOptions)
706+
.call(cwd = root, stderr = os.Pipe)
707+
expect(result.exitCode == 0)
708+
expect(!result.err.text().contains("cannot post process TASTY files"))
709+
}
710+
}
700711
}
Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
package scala.build.tastylib
22

33
import scala.build.tastylib.internal.Constants
4+
import scala.util.Try
45

56
object TastyVersions {
7+
implicit class VersionOps(version: String) {
8+
def majorVersion: Int = version.split('.')(0).toInt
9+
def minorVersion: Int = version.split('.')(1).toInt
10+
def minorVersionOption: Option[Int] = Try(minorVersion).toOption
11+
}
612

713
// Every time tasty version is updated, please update LatestSupportedScala as well!
8-
object LatestSupportedScala {
9-
final val MajorVersion: Int = 3
10-
final val MinorVersion: Int = Constants.latestSupportedScala.split('.')(1).toInt
14+
private object LatestSupportedScala {
15+
final val MajorVersion: Int = Constants.latestSupportedScala.majorVersion
16+
final val MinorVersion: Int = Constants.latestSupportedScala.minorVersion
17+
18+
def isLatestSupportedMajorVersion(scalaVersion: String): Boolean =
19+
scalaVersion.startsWith(s"${LatestSupportedScala.MajorVersion}.") ||
20+
scalaVersion == LatestSupportedScala.MajorVersion.toString
1121
}
1222

1323
def shouldRunPreprocessor(
1424
scalaVersion: String,
1525
scalaCliVersion: String
1626
): Either[String, Boolean] =
17-
if (!scalaVersion.startsWith("3.") && scalaVersion != "3") Right(false)
18-
else
19-
scalaVersion.split('.')(1).toInt match {
20-
case scalaMinor if scalaMinor > LatestSupportedScala.MinorVersion =>
21-
Left(
22-
s"Scala CLI (v. $scalaCliVersion) cannot post process TASTY files from Scala $scalaVersion.\n" +
23-
s"This is not a fatal error since post processing only cleans up source paths in TASTY file " +
24-
s"and it should not affect your application.\n" +
25-
s"To get rid of this message, please update Scala CLI version."
26-
)
27-
case _ =>
28-
Right(true)
29-
}
27+
if (!LatestSupportedScala.isLatestSupportedMajorVersion(scalaVersion)) Right(false)
28+
else scalaVersion.minorVersionOption match {
29+
case Some(scalaMinor) if scalaMinor > LatestSupportedScala.MinorVersion =>
30+
Left(
31+
s"""Scala CLI (v$scalaCliVersion) cannot post process TASTY files from Scala $scalaVersion.
32+
|This is not a fatal error since post processing only cleans up source paths in TASTY file.
33+
|It should not affect your application.
34+
|You may be getting this warning because you are using a newer version of Scala than the one supported by Scala CLI (v$scalaCliVersion).
35+
|Make sure your Scala CLI is up-to-date.
36+
|You may need to wait for $scalaVersion support in a future version of Scala CLI.
37+
|""".stripMargin
38+
)
39+
case _ => Right(true)
40+
}
3041
}

0 commit comments

Comments
 (0)