Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
philwalk opened this issue Mar 16, 2021 · 0 comments · Fixed by #11777
Assignees

Comments

@philwalk
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants