Skip to content

Backport "Fix #21242: Add REPL flag to quit after evaluating init script" to 3.3 LTS #272

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 8 commits into from
Apr 23, 2025
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
6 changes: 6 additions & 0 deletions bin/replQ
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >& /dev/null && pwd)/.."
. $ROOT/bin/commonQ

java -Dscala.usejavacp=true -cp $cp dotty.tools.repl.Main -usejavacp "$@"
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ trait CommonScalaSettings:
val usejavacp: Setting[Boolean] = BooleanSetting("-usejavacp", "Utilize the java.class.path in classpath resolution.", aliases = List("--use-java-class-path"))
val scalajs: Setting[Boolean] = BooleanSetting("-scalajs", "Compile in Scala.js mode (requires scalajs-library.jar on the classpath).", aliases = List("--scalajs"))
val replInitScript: Setting[String] = StringSetting("-repl-init-script", "code", "The code will be run on REPL startup.", "", aliases = List("--repl-init-script"))
val replQuitAfterInit: Setting[Boolean] = BooleanSetting("-repl-quit-after-init", "Quit REPL after evaluating the init script.", aliases = List("--repl-quit-after-init"))

end CommonScalaSettings

Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ class ReplDriver(settings: Array[String],
*
* Possible reason for unsuccessful run are raised flags in CLI like --help or --version
*/
final def tryRunning = if shouldStart then runUntilQuit()
final def tryRunning = if shouldStart then
if rootCtx.settings.replQuitAfterInit.value(using rootCtx) then initialState
else runUntilQuit()

/** Run REPL with `state` until `:quit` command found
*
Expand Down