Skip to content

Commit

Permalink
Fix the REPL crashing when a dependency's classpath is called by a ma…
Browse files Browse the repository at this point in the history
…cro (#3043)
  • Loading branch information
Gedochao authored Jul 22, 2024
1 parent 601e9f6 commit daa8b27
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
14 changes: 8 additions & 6 deletions modules/cli/src/main/scala/scala/cli/commands/repl/Repl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -394,23 +394,25 @@ object Repl extends ScalaCommand[ReplOptions] with BuildCommandHelpers {
if (dryRun)
logger.message("Dry run, not running REPL.")
else {
val isAmmonite = replArtifacts.replMainClass.startsWith("ammonite")
val depClassPathArgs: Seq[String] =
if replArtifacts.depsClassPath.nonEmpty && !replArtifacts.replMainClass.startsWith(
"ammonite"
)
then
if replArtifacts.depsClassPath.nonEmpty && !isAmmonite then
Seq(
"-classpath",
replArtifacts.depsClassPath.map(_.toString).mkString(File.pathSeparator)
(mainJarsOrClassDirs ++ replArtifacts.depsClassPath)
.map(_.toString).mkString(File.pathSeparator)
)
else Nil
val replLauncherClasspath =
if isAmmonite then mainJarsOrClassDirs ++ replArtifacts.replClassPath
else replArtifacts.replClassPath
val retCode = Runner.runJvm(
javaCommand = options.javaHome().value.javaCommand,
javaArgs = scalapyJavaOpts ++
replArtifacts.replJavaOpts ++
options.javaOptions.javaOpts.toSeq.map(_.value.value) ++
extraProps.toVector.sorted.map { case (k, v) => s"-D$k=$v" },
classPath = mainJarsOrClassDirs ++ replArtifacts.replClassPath,
classPath = replLauncherClasspath,
mainClass = replArtifacts.replMainClass,
args = maybeAdaptForWindows(depClassPathArgs ++ replArgs),
logger = logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import scala.util.Properties

abstract class ReplTestDefinitions extends ScalaCliSuite with TestScalaVersionArgs {
_: TestScalaVersion =>
private lazy val extraOptions = scalaVersionArgs ++ TestUtil.extraOptions
protected lazy val extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions

private val retrieveScalaVersionCode = if (actualScalaVersion.startsWith("2."))
"scala.util.Properties.versionNumberString"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package scala.cli.integration

import com.eed3si9n.expecty.Expecty.expect

import scala.util.Properties

trait ReplTests3StableDefinitions { _: ReplTestDefinitions =>
if (!actualScalaVersion.equals(actualMaxAmmoniteScalaVersion)) {
lazy val defaultScalaVersionString =
Expand All @@ -16,4 +20,31 @@ trait ReplTests3StableDefinitions { _: ReplTestDefinitions =>
ammoniteTestScope(useMaxAmmoniteScalaVersion = false)
}
}

test("https://github.com/scala/scala3/issues/21229") {
TestInputs(
os.rel / "Pprint.scala" ->
"""//> using dep "com.lihaoyi::pprint::0.9.0"
|package stuff
|import scala.quoted.*
|def foo = pprint(1)
|inline def bar = pprint(1)
|inline def baz = ${ bazImpl }
|def bazImpl(using Quotes) = '{ pprint(1) }
|""".stripMargin
).fromRoot { root =>
val ammArgs = Seq("-c", "println(stuff.baz)")
.map {
if (Properties.isWin)
a => if (a.contains(" ")) "\"" + a.replace("\"", "\\\"") + "\"" else a
else
identity
}
.flatMap(arg => Seq("--ammonite-arg", arg))
// FIXME: test this on standard Scala 3 REPL, rather than just Ammonite
val res = os.proc(TestUtil.cli, "repl", ".", "--power", "--amm", ammArgs, extraOptions)
.call(cwd = root)
expect(res.out.trim().nonEmpty)
}
}
}

0 comments on commit daa8b27

Please sign in to comment.