Skip to content

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

@philwalk

Description

@philwalk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions