Skip to content

Commit 9e35d82

Browse files
som-snyttsmarter
authored andcommitted
Runner sets residual args instead of append
1 parent 4133c62 commit 9e35d82

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

compiler/src/dotty/tools/MainGenericRunner.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ object MainGenericRunner {
169169
else
170170
val newSettings = if arg.startsWith("-") then settings else settings.withPossibleEntryPaths(arg).withModeShouldBePossibleRun
171171
process(tail, newSettings.withResidualArgs(arg))
172-
172+
end process
173173

174174
def main(args: Array[String]): Unit =
175175
val scalaOpts = envOrNone("SCALA_OPTS").toArray.flatMap(_.split(" ")).filter(_.nonEmpty)
@@ -200,8 +200,7 @@ object MainGenericRunner {
200200
Option.when(Jar.isJarOrZip(dotty.tools.io.Path(entryPath)))(Jar(entryPath).mainClass).flatten
201201
}.isDefined
202202
}
203-
val newSettings =
204-
targetToRun match
203+
val newSettings = targetToRun match
205204
case Some(fqName) =>
206205
settings.withTargetToRun(fqName).copy(residualArgs = settings.residualArgs.filterNot(fqName.==)).withExecuteMode(ExecuteMode.Run)
207206
case None =>

tests/run-with-compiler/i14541.check

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

tests/run-with-compiler/i14541.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11

2+
// test argument processing and "execution mode" in runner
23
object Test:
34
import dotty.tools.runner.RichClassLoader.*
4-
def main(args: Array[String]): Unit = getClass.getClassLoader.run("echo", List("hello", "world"))
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"))
510

611
@main def echo(args: String*): Unit = println {
712
args.mkString(" ")

0 commit comments

Comments
 (0)