Skip to content

Commit efc637e

Browse files
Merge pull request #14543 from som-snytt/issue/14541
Runner sets residual args instead of append
2 parents 859214a + 01a4919 commit efc637e

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

compiler/src/dotty/tools/MainGenericRunner.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ object MainGenericRunner {
168168
else
169169
val newSettings = if arg.startsWith("-") then settings else settings.withPossibleEntryPaths(arg).withModeShouldBePossibleRun
170170
process(tail, newSettings.withResidualArgs(arg))
171-
171+
end process
172172

173173
def main(args: Array[String]): Unit =
174174
val scalaOpts = envOrNone("SCALA_OPTS").toArray.flatMap(_.split(" ")).filter(_.nonEmpty)
@@ -199,11 +199,12 @@ object MainGenericRunner {
199199
Option.when(Jar.isJarOrZip(dotty.tools.io.Path(entryPath)))(Jar(entryPath).mainClass).flatten
200200
}.isDefined
201201
}
202-
targetToRun match
202+
val newSettings = targetToRun match
203203
case Some(fqName) =>
204-
run(settings.withTargetToRun(fqName).withResidualArgs(settings.residualArgs.filter { _ != fqName }*).withExecuteMode(ExecuteMode.Run))
204+
settings.withTargetToRun(fqName).copy(residualArgs = settings.residualArgs.filterNot(fqName.==)).withExecuteMode(ExecuteMode.Run)
205205
case None =>
206-
run(settings.withExecuteMode(ExecuteMode.Repl))
206+
settings.withExecuteMode(ExecuteMode.Repl)
207+
run(newSettings)
207208
case ExecuteMode.Run =>
208209
val scalaClasspath = ClasspathFromClassloader(Thread.currentThread().getContextClassLoader).split(classpathSeparator)
209210
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)