Description
Compiler version
Scala code runner version 3.1.1-RC1-bin-SNAPSHOT-git-3f978b3 -- Copyright 2002-2021, LAMP/EPFL
Minimized code
Here's the bug and the one-line fix.
On line 108 of MainGenericRunner:
val globdir = cp.replaceAll("[\\/][^\\/]*$", "") // slash/backslash agnostic
the regex should have quadruple backslashes, like this:
val globdir = cp.replaceAll("[\\\\/][^\\\\/]*$", "") // slash/backslash agnostic
The following script fails to compile without the fix:
#!bin/scala -classpath 'dist/target/pack/lib/*'
// import won't compile unless the hashbang line is effective in setting the classpath
import org.jline.terminal.Terminal
def main(args: Array[String]) =
val cp = sys.props("java.class.path")
printf("unglobbed classpath:\n%s\n", cp)
Added a test to verify this fix in dotty.tools.scripting.ClasspathTests
Output
Because the wildcard classpath is explanded by dist/bin/scala
, only the first jar in the glob expansion becomes the classpath entry, and all others are added as command line arguments (jar files are intepreted by compiler as scala sources).
The attempt to run the script results in 456763 lines of error messages. Here are the last few lines:
-------------------------------------------------------------------------
3917 |v�RH�����֍Yݘ��1���Dw���(P�xNa��Q� �0Q�N�T=���`NŔ�qv:HE˧��)n�Yh&��(vt���μc�8�}����y�D�r��h�՞��hLמ���~�)����Q�V�a��ʕ�1��i�Fy\���B�X�*��Y͠�B[��pD�l!�ѣX
|^
|Line is indented too far to the left, or a `}` is missing
-- Warning: dist/target/pack/lib/protobuf-java-3.7.0.jar:6246:0 ----------------------------------------------------------------------------------------------------------------------------------------------
6246 |��*�n��@�0gb���ΛT���,"�zG�0���Q�-
|^
|Line is indented too far to the left, or a `}` is missing
-- Warning: dist/target/pack/lib/protobuf-java-3.7.0.jar:14210:0 ---------------------------------------------------------------------------------------------------------------------------------------------
14210 |��(��"~A+
|^
|Line is indented too far to the left, or a `}` is missing
-- Warning: dist/target/pack/lib/protobuf-java-3.7.0.jar:16269:0 ---------------------------------------------------------------------------------------------------------------------------------------------
16269 |��U�κCgъ��[<NH��p�U�o����d�T�Tڬ{J,x�
|^
|Line is indented too far to the left, or a `}` is missing
7 warnings found
114151 errors found
Error: Errors encountered during compilation
Expectation
Script should run without error, printing something like the following:
unglobbed classpath: C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala-library-2.13.6.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala3-library_3-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala-asm-9.1.0-scala-1.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/compiler-interface-1.3.5.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala3-interfaces-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala3-compiler_3-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/tasty-core_3-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala3-staging_3-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/scala3-tasty-inspector_3-3.1.1-RC1-bin-SNAPSHOT.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/jline-reader-3.19.0.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/jline-terminal-3.19.0.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/jline-terminal-jna-3.19.0.jar;C:/Users/philwalk/workspace/newPR-dotty/dist/target/pack/lib/jna-5.3.1.jar;;
The fix plus unit tests to verify it will be submitted as a PR very soon.
NOTE: the reason the error is specific to Windows is due to the fact that the half-quotes surrounding the wildcard classpath in the hashbang line of the script prevent globbing in Linux and other environments, but not in Windows.
In the scala3-3.0.2 release (and earlier), this bug was fixed by appending a semicolon to wildcard classpath arguments.