Skip to content

scalac can consume arguments intended to be passed to a script, and can execute the wrong script #11776

Closed
@philwalk

Description

@philwalk

Compiler version

Scala compiler version 3.0.0-RC2-bin-SNAPSHOT-git-4bfa802 -- Copyright 2002-2021, LAMP/EPFL

Minimized code

The following command line demonstrates the problem. It should execute script1.sc and pass the remaining arguments to script1.sc, but instead it executes script2.sc:

scalac -script script1.sc -script script2.sc

The bug manifests itself if the target_script also uses -script or -repl arguments, etc.

The problem is hidden as long as script2.sc never is passed any arguments that can be consumed by dist/bin/scalac.

Output

The command line executes script2.sc rather than script1.sc.

Expectation

The command line should execute script1.sc instead of script2.sc.

A simple fix is for all remaining arguments to be consumed as soon as in_scripting_args is set.

         -repl) PROG_NAME="$ReplMain" && shift ;;
-      -script) PROG_NAME="$ScriptingMain" && target_script="$2" && in_scripting_args=true && shift && shift ;;
+      -script) PROG_NAME="$ScriptingMain" && target_script="$2" && in_scripting_args=true && shift && shift
+               while [[ $# -gt 0 ]]; do addScripting "$1" && shift ; done ;;
      -compile) PROG_NAME="$CompilerMain" && shift ;;

We should also remove in_scripting_args as it's not needed.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions