Skip to content

Commit 2cc3070

Browse files
committed
Runner sets residual args instead of append
1 parent 5109909 commit 2cc3070

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

compiler/src/dotty/tools/MainGenericRunner.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,10 @@ object MainGenericRunner {
166166
.withTargetScript(arg)
167167
.withScriptArgs(tail*)
168168
else
169-
val newSettings = if arg.startsWith("-") then settings else settings.withPossibleEntryPaths(arg).withModeShouldBePossibleRun
170-
process(tail, newSettings.withResidualArgs(arg))
171-
169+
val modalSettings = if arg.startsWith("-") then settings else settings.withPossibleEntryPaths(arg).withModeShouldBePossibleRun
170+
val newSettings = modalSettings.withResidualArgs(arg)
171+
process(tail, newSettings)
172+
end process
172173

173174
def main(args: Array[String]): Unit =
174175
val scalaOpts = envOrNone("SCALA_OPTS").toArray.flatMap(_.split(" ")).filter(_.nonEmpty)
@@ -199,11 +200,13 @@ object MainGenericRunner {
199200
Option.when(Jar.isJarOrZip(dotty.tools.io.Path(entryPath)))(Jar(entryPath).mainClass).flatten
200201
}.isDefined
201202
}
202-
targetToRun match
203+
val newSettings =
204+
targetToRun match
203205
case Some(fqName) =>
204-
run(settings.withTargetToRun(fqName).withResidualArgs(settings.residualArgs.filter { _ != fqName }*).withExecuteMode(ExecuteMode.Run))
206+
settings.withTargetToRun(fqName).copy(residualArgs = settings.residualArgs.filterNot(fqName.==)).withExecuteMode(ExecuteMode.Run)
205207
case None =>
206-
run(settings.withExecuteMode(ExecuteMode.Repl))
208+
settings.withExecuteMode(ExecuteMode.Repl)
209+
run(newSettings)
207210
case ExecuteMode.Run =>
208211
val scalaClasspath = ClasspathFromClassloader(Thread.currentThread().getContextClassLoader).split(classpathSeparator)
209212
val newClasspath = (settings.classPath.flatMap(_.split(classpathSeparator).filter(_.nonEmpty)) ++ removeCompiler(scalaClasspath) :+ ".").map(File(_).toURI.toURL)

tests/run-with-compiler/i14541.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
hello raw world
2+
hello run world

tests/run-with-compiler/i14541.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
// test argument processing and "execution mode" in runner
3+
object Test:
4+
import dotty.tools.runner.RichClassLoader.*
5+
val classpath = dotty.tools.dotc.util.ClasspathFromClassloader(getClass.getClassLoader)
6+
def main(args: Array[String]): Unit =
7+
getClass.getClassLoader.run("echo", List("hello", "raw", "world"))
8+
// caution: uses "SCALA_OPTS"
9+
dotty.tools.MainGenericRunner.main(Array("--class-path", classpath, "echo", "hello", "run", "world"))
10+
11+
@main def echo(args: String*): Unit = println {
12+
args.mkString(" ")
13+
}

0 commit comments

Comments
 (0)