Skip to content

Commit 8046be1

Browse files
authored
Add support for the new Scala 3.8 REPL (#3936)
1 parent 248d998 commit 8046be1

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

modules/build/src/main/scala/scala/build/ReplArtifacts.scala

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,28 @@ object ReplArtifacts {
9393
addScalapy: Option[String],
9494
javaVersion: Int
9595
): Either[BuildException, ReplArtifacts] = either {
96-
val isScala2 = scalaParams.scalaVersion.startsWith("2.")
97-
val replDep =
98-
if isScala2 then dep"org.scala-lang:scala-compiler:${scalaParams.scalaVersion}"
99-
else dep"org.scala-lang::scala3-compiler:${scalaParams.scalaVersion}"
96+
val isScala2 = scalaParams.scalaVersion.startsWith("2.")
97+
val firstNewReplNightly = "3.8.0-RC1-bin-20251101-389483e-NIGHTLY".coursierVersion
98+
val firstNewReplRc = "3.8.0-RC1".coursierVersion
99+
val firstNewReplStable = "3.8.0".coursierVersion
100+
val scalaCoursierVersion = scalaParams.scalaVersion.coursierVersion
101+
val shouldUseNewRepl =
102+
!isScala2 &&
103+
((scalaCoursierVersion >= firstNewReplNightly) || (scalaCoursierVersion >= firstNewReplRc) || scalaCoursierVersion >= firstNewReplStable)
104+
val replDeps =
105+
if isScala2 then Seq(dep"org.scala-lang:scala-compiler:${scalaParams.scalaVersion}")
106+
else if shouldUseNewRepl then
107+
Seq(
108+
dep"org.scala-lang::scala3-compiler:${scalaParams.scalaVersion}",
109+
dep"org.scala-lang::scala3-repl:${scalaParams.scalaVersion}"
110+
)
111+
else Seq(dep"org.scala-lang::scala3-compiler:${scalaParams.scalaVersion}")
100112
val scalapyDeps =
101113
addScalapy.map(ver => dep"${Artifacts.scalaPyOrganization(ver)}::scalapy-core::$ver").toSeq
102114
val externalDeps = dependencies ++ scalapyDeps
103115
val replArtifacts: Seq[(String, os.Path)] = value {
104116
Artifacts.artifacts(
105-
Seq(replDep).map(Positioned.none),
117+
replDeps.map(Positioned.none),
106118
repositories,
107119
Some(scalaParams),
108120
logger,
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
11
package scala.cli.integration
22

3-
class ReplTests3NextRc extends ReplTestDefinitions with Test3NextRc
3+
import com.eed3si9n.expecty.Expecty.expect
4+
5+
class ReplTests3NextRc extends ReplTestDefinitions with Test3NextRc {
6+
test("run hello world from the 3.8 REPL") {
7+
TestInputs.empty.fromRoot { root =>
8+
val expectedMessage = "1337"
9+
val code = s"""println($expectedMessage)"""
10+
val r = os.proc(
11+
TestUtil.cli,
12+
"repl",
13+
"--repl-quit-after-init",
14+
"--repl-init-script",
15+
code,
16+
"-S",
17+
// TODO: switch this test to 3.8.0-RC1 once it's out
18+
"3.8.0-RC1-bin-20251104-b83b3d9-NIGHTLY",
19+
TestUtil.extraOptions
20+
)
21+
.call(cwd = root)
22+
expect(r.out.trim() == expectedMessage)
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)