Open
Description
Compiler version
# scala -version
Scala code runner version 3.4.0-RC1 -- Copyright 2002-2023, LAMP/EPFL
# java -version
openjdk version "19" 2022-09-20
OpenJDK Runtime Environment (build 19+36-2238)
OpenJDK 64-Bit Server VM (build 19+36-2238, mixed mode, sharing)
Minimized code
The scala script below crashes the compiler if called as described.
Name the script ./vsortBug.sc
and attempt to run it with this bash script:
#!/bin/bash
SCALA_HOME="C:/opt/scala3-3.4.0-RC1"
PATH="$SCALA_HOME/bin:$PATH"
echo "-cp C:/opt/scala3-3.3.1/lib/scala3-library_3-3.3.1.jar" > bugAtfile
SCALA_OPTS=@bugAtfile ./vsortBug.sc
I have a classpath @file
with dozens of entries, and I eventually discovered a compiler lib file from an incompatible version, scala3-library_3-3.3.1.jar
towards the end, so this is not a compiler bug, although it might be worthwhile to immunize against this category of bug somehow.
It's not surprising that launching the script with scala3-3.4.0-RC1
leads to a crash, although it took awhile to figure out root cause.
Possible fixes: when incompatible compiler jars appear in the classpath:
- issue warnings
- filter them out
- replace them with correctly versioned equivalents
- close this issue with no changes
If the runtime version scala3-library_3-3.4.0-RC1.jar
appears earlier in the classpath
, no crash.
#!/usr/bin/env -S scala
object VersionSort {
def main(_args: Array[String]): Unit =
println("hello")
case class PathString(path: String) extends Ordered[PathString] {
val fields = path.split("[\\D]+").toList.map {
case num if num.trim.matches("[0-9]+") => "%010f".format(num.toDouble)
case str => str
} // .mkString("| ")
//printf("%s [%s]\n", path, fields.mkString("|"))
override def toString = path
// compare subfields fields
def compare(other: PathString): Int = {
var i = 0
val of = other.fields
val tf = this.fields
val maxindex = of.size.min(tf.size) -1
var num = 0
while (i <= maxindex && num == 0) {
num = tf(i) compare of(i)
i += 1
}
num
}
}
}
Output (click arrow to expand)
When the classpath
echo "-cp C:/Users/philwalk/AppData/Local/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.3.1/scala3-library_3-3.3.1.jar" > bugAtfile
SCALA_OPTS=@bugAtfile jsrc/vsortBug.sc 2>&1 | tee s124
unhandled exception while running MegaPhase{protectedAccessors, extmethods, uncacheGivenAliases, elimByName, hoistSuperArgs, forwardDepChecks, specializeApplyMethods, tryCatchPatterns, patternMatcher} on C:\opt\ue\jsrc\vsortBug.sc
An unhandled exception was thrown in the compiler.
Please file a crash report here:
https://github.com/lampepfl/dotty/issues/new/choose
For non-enriched exceptions, compile with -Yno-enrich-error-messages.
while compiling: C:\opt\ue\jsrc\vsortBug.sc
during phase: MegaPhase{protectedAccessors, extmethods, uncacheGivenAliases, elimByName, hoistSuperArgs, forwardDepChecks, specializeApplyMethods, tryCatchPatterns, patternMatcher}
mode: Mode(ImplicitsEnabled)
library version: version 2.13.12
compiler version: version 3.4.0-RC1
settings: -classpath C:/Users/philwalk/AppData/Local/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.3.1/scala3-library_3-3.3.1.jar;C:/opt/scala/lib/scala-library-2.13.12.jar;C:/opt/scala/lib/scala3-library_3-3.4.0-RC1.jar;C:/opt/scala/lib/scala-asm-9.6.0-scala-1.jar;C:/opt/scala/lib/compiler-interface-1.9.3.jar;C:/opt/scala/lib/scala3-interfaces-3.4.0-RC1.jar;C:/opt/scala/lib/scala3-compiler_3-3.4.0-RC1.jar;C:/opt/scala/lib/tasty-core_3-3.4.0-RC1.jar;C:/opt/scala/lib/scala3-staging_3-3.4.0-RC1.jar;C:/opt/scala/lib/scala3-tasty-inspector_3-3.4.0-RC1.jar;C:/opt/scala/lib/jline-reader-3.19.0.jar;C:/opt/scala/lib/jline-terminal-3.19.0.jar;C:/opt/scala/lib/jline-terminal-jna-3.19.0.jar;C:/opt/scala/lib/jna-5.3.1.jar -d C:\tmp\scala3-scripting10473104943302070702
Exception in thread "main" dotty.tools.dotc.core.TypeError$$anon$1: object caps does not have a member type Cap