relax requirements for recognizing valid scala hashbang lines - fix for #13670 #13671
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
This PR changes the current strict requirement that a hashbang line MUST end with "scala" in order to be recognized as a valid scala script.
The problem will only manifested if the script filename extension is neither
.scalanor.sc, and the hashbang line has characters following "scala".For example, if the hashbang line also provides a -classpath argument following "scala", the script name is not recognized as a valid script, and the REPL is entered.
Example:
A valid scala script named
finderwith these contents:Rather than executing the script, the current behavior is to enter the REPL.
The proposed fix is to consider a file to be a valid scala script if the first line of the file has these features:
Although a workaround is to rename the file (e.g., to
finder.scrather thanfinder), this is restricive, because it prevents scala scripts from from shadowing command line tools written in other languages.This regression was introduced after
scala3-3.0.2.