Skip to content

Commit

Permalink
Runner sets residual args instead of append
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Feb 22, 2022
1 parent c923db2 commit b9ec198
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/MainGenericRunner.scala
Expand Up @@ -199,11 +199,13 @@ object MainGenericRunner {
Option.when(Jar.isJarOrZip(dotty.tools.io.Path(entryPath)))(Jar(entryPath).mainClass).flatten
}.isDefined
}
targetToRun match
val newSettings =
targetToRun match
case Some(fqName) =>
run(settings.withTargetToRun(fqName).withResidualArgs(settings.residualArgs.filter { _ != fqName }*).withExecuteMode(ExecuteMode.Run))
settings.withTargetToRun(fqName).copy(residualArgs = settings.residualArgs.filterNot(fqName.==)).withExecuteMode(ExecuteMode.Run)
case None =>
run(settings.withExecuteMode(ExecuteMode.Repl))
settings.withExecuteMode(ExecuteMode.Repl)
run(newSettings)
case ExecuteMode.Run =>
val scalaClasspath = ClasspathFromClassloader(Thread.currentThread().getContextClassLoader).split(classpathSeparator)
val newClasspath = (settings.classPath.flatMap(_.split(classpathSeparator).filter(_.nonEmpty)) ++ removeCompiler(scalaClasspath) :+ ".").map(File(_).toURI.toURL)
Expand Down
1 change: 1 addition & 0 deletions tests/run-with-compiler/i14541.check
@@ -0,0 +1 @@
hello world
8 changes: 8 additions & 0 deletions tests/run-with-compiler/i14541.scala
@@ -0,0 +1,8 @@

object Test:
import dotty.tools.runner.RichClassLoader.*
def main(args: Array[String]): Unit = getClass.getClassLoader.run("echo", List("hello", "world"))

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

0 comments on commit b9ec198

Please sign in to comment.