Skip to content

Fix the REPL crashing when a dependency's classpath is called by a macro #3043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}
Loading