Skip to content

Commit 0c340bc

Browse files
committed
Fix running REPL from the shell script
1 parent 72c279f commit 0c340bc

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

compiler/src/dotty/tools/MainGenericRunner.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ case class Settings(
2727
scriptArgs: List[String] = List.empty,
2828
targetScript: String = "",
2929
save: Boolean = false,
30+
modeShouldBeRun: Boolean = false,
3031
) {
3132
def withExecuteMode(em: ExecuteMode): Settings = this.executeMode match
3233
case ExecuteMode.Guess =>
@@ -58,6 +59,9 @@ case class Settings(
5859

5960
def withSave: Settings =
6061
this.copy(save = true)
62+
63+
def withModeShouldBeRun: Settings =
64+
this.copy(modeShouldBeRun = true)
6165
}
6266

6367
object MainGenericRunner {
@@ -99,7 +103,8 @@ object MainGenericRunner {
99103
.withTargetScript(arg)
100104
.withScriptArgs(tail*)
101105
else
102-
process(tail, settings.withResidualArgs(arg))
106+
val newSettings = if arg.startsWith("-") then settings else settings.withModeShouldBeRun
107+
process(tail, newSettings.withResidualArgs(arg))
103108

104109
def main(args: Array[String]): Unit =
105110
val settings = process(args.toList, Settings())
@@ -127,10 +132,10 @@ object MainGenericRunner {
127132
++ settings.scriptArgs
128133
scripting.Main.main(properArgs.toArray)
129134
case ExecuteMode.Guess =>
130-
if args.toList.forall(_.startsWith("-")) then // all are options
131-
run(ExecuteMode.Repl)
132-
else
135+
if settings.modeShouldBeRun then
133136
run(ExecuteMode.Run)
137+
else
138+
run(ExecuteMode.Repl)
134139

135140
run(settings.executeMode)
136141

compiler/test-coursier/dotty/tools/coursier/CoursierScalaTests.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ class CoursierScalaTests:
7272
assertEquals(output.mkString("\n"), "Hello")
7373
notOnlyOptionsEqualsRun()
7474

75+
def help() =
76+
val output = CoursierScalaTests.csCmd("-help")
77+
assertTrue(output.mkString("\n").contains("Usage: scala <options> <source files>"))
78+
help()
79+
7580
def jar() =
7681
val source = new File(getClass.getResource("/run/myfile.scala").getPath)
7782
val output = CoursierScalaTests.csCmd("-save", source.absPath)

0 commit comments

Comments
 (0)