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 borks on shebangs #5179

Closed
scabug opened this issue Nov 11, 2011 · 3 comments
Closed

scalac borks on shebangs #5179

scabug opened this issue Nov 11, 2011 · 3 comments

Comments

@scabug
Copy link

scabug commented Nov 11, 2011

The interpreter (scala) allows shebangs for convenience. For example:

Hello.scala:

#!/usr/bin/env sh
exec scala "$0" "$@"
!#

object Hello {
def main(args: Array[String]) {
println("Hello World!")
}
}

$ chmod a+x Hello.scala
$ ./Hello.scala
Hello World!

However, the compiler (scalac) strangely does not accept shebangs.

$ scalac Hello.scala
Hello.scala:1: error: expected class or object definition
#!/usr/bin/env sh
^
Hello.scala:2: error: expected class or object definition
exec scala "$0" "$@"
^
Hello.scala:3: error: expected class or object definition
!#
^
three errors found

This creates an artificial distinction between Scala scripts and Scala programs, forcing programmers to choose one or the other. And when a programmer uses someone else's code, he'd rather not have to manually add or remove shebang lines to make scala and scalac happy.

Fortunately, the solution is simple: Have scalac consider shebang lines as comments. Anything between #! and !# is just a comment.

@scabug
Copy link
Author

scabug commented Nov 11, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5179?orig=1
Reporter: Andrew Pennebaker (mcandre)
Affected Versions: 2.9.1

@scabug
Copy link
Author

scabug commented Jan 19, 2013

Andrew Pennebaker (mcandre) said:
Why is this STILL unresolved? Just treat shebangs as comments in scalac!

@scabug
Copy link
Author

scabug commented Jan 19, 2013

@retronym said:
A change to the Scala parser (even just for a new comment syntax) would need to be first discussed on the scala-language mailing list. There are many tools upstream (IDEs, editors) that are affected by such a change, so it isn't taken lightly.

Closing this as "out of scope" pending such discussion.

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

No branches or pull requests

2 participants