Skip to content

fix: need to capture all scripting args when script arg is detected #12422

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

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions dist/bin/scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,34 +118,35 @@ while [[ $# -gt 0 ]]; do
shift ;;

*)
if [ "${execute_mode-}" == 'script' ]; then
addScript "$1"
else
# script if extension .scala or .sc, or if has scala hashbang line

# no -f test, issue meaningful error message (file not found)
if [[ "$1" == *.scala || "$1" == *.sc ]]; then
setExecuteMode 'script' # execute_script=true

# -f test needed before we examine the hashbang line
elif [[ (-f "$1" && `head -n 1 -- "$1" | grep '#!.*scala'`) ]]; then
setExecuteMode 'script' # execute_script=true
fi
# script if extension .scala or .sc, or if has scala hashbang line
# no -f test, issue meaningful error message (file not found)
if [[ "$1" == *.scala || "$1" == *.sc ]]; then
setExecuteMode 'script' # execute_script=true

# -f test needed before we examine the hashbang line
elif [[ (-f "$1" && `head -n 1 -- "$1" | grep '#!.*scala'`) ]]; then
setExecuteMode 'script' # execute_script=true
fi

if [ "${execute_mode-}" == 'script' ]; then
target_script="$1"
if [ ! -f $target_script ]; then
# likely a typo or missing script file, quit early
echo "not found: $target_script" 1>&2
scala_exit_status=2
onExit
fi
else
# all unrecognized args appearing prior to a script name
addResidual "$1"
if [ "${execute_mode-}" == 'script' ]; then
target_script="$1"
shift
if [ ! -f $target_script ]; then
# likely a typo or missing script file, quit early
echo "not found: $target_script" 1>&2
scala_exit_status=2
onExit
fi
# all are script args
while [[ $# -gt 0 ]]; do
addScript "${1}"
shift
done
else
# all unrecognized args appearing prior to a script name
addResidual "$1"
shift
fi
shift
;;

esac
Expand Down
4 changes: 2 additions & 2 deletions dist/bin/scalac
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ case "$1" in
-Oshort) addJava "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" && shift ;;
-repl) PROG_NAME="$ReplMain" && shift ;;
-script) PROG_NAME="$ScriptingMain" && target_script="$2" && shift && shift
while [[ $# -gt 0 ]]; do addScripting "$1" && shift ; done ;;
while [[ $# -gt 0 ]]; do addScript "$1" && shift ; done ;;
-compile) PROG_NAME="$CompilerMain" && shift ;;
-decompile) PROG_NAME="$DecompilerMain" && shift ;;
-print-tasty) PROG_NAME="$DecompilerMain" && addScala "-print-tasty" && shift ;;
Expand All @@ -64,7 +64,7 @@ compilerJavaClasspathArgs

if [ "$PROG_NAME" == "$ScriptingMain" ]; then
setScriptName="-Dscript.path=$target_script"
scripting_string="-script $target_script ${scripting_args[@]}"
scripting_string="-script $target_script ${script_args[@]}"
fi

[ -n "$script_trace" ] && set -x
Expand Down