Skip to content

check for recognizing a valid scala hashbang line is too strict #13670

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
philwalk opened this issue Oct 3, 2021 · 0 comments · Fixed by #13671
Closed

check for recognizing a valid scala hashbang line is too strict #13670

philwalk opened this issue Oct 3, 2021 · 0 comments · Fixed by #13671

Comments

@philwalk
Copy link
Contributor

philwalk commented Oct 3, 2021

Compiler version

Scala code runner version 3.1.1-RC1-bin-SNAPSHOT-git-bf753c7 -- Copyright 2002-2021, LAMP/EPFL

Minimized code

#!/usr/bin/env scala3
println("hello, world")

Output

Welcome to Scala 3.1.1-RC1-bin-SNAPSHOT-git-bf753c7 (16.0.2, Java Java HotSpot(TM) 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala>

Expectation

Assuming scala3 script in PATH redirects to dist\bin\scala, it should run the script and print "hello, world".
Instead it enters the REPL.

The problem occurs whenever a script hashbang line ends with anything other than exactly "scala".
In the example script above, a wrapper script called scala3 would redirect correctly, but is not recognized as a scala hashbang.

In MainGenericRunner line 149, the test for whether a command line argument is a scala script is needlessly restrictive:

      if arg.endsWith(".scala") || arg.endsWith(".sc") || (line.nonEmpty && raw"#!.*scala".r.matches(line.get)) then

The regex doesn't permit any characters following "scala".

This is a regression that affects release candidates later than scala3-3.0.2, such as scala3-3.1.0-RC2.

BarkingBad added a commit that referenced this issue Oct 4, 2021
…g-recognizer

relax requirements for recognizing valid scala hashbang lines - fix for #13670
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
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