I’m trying to run my project tests from sbt at the command line with “sbt test”.
But I get errors that I don’t understand.
Does anyone have an idea of what’s happening here?
I’m not sure whether this is related to another issue, that I cannot run the tests en masse from IntelliJ.
[geminiani:~/Repos/regular-type-expression/cl-robdd-scala] jimka% sbt test
[info] Loading settings for project global-plugins from idea.sbt ...
[info] Loading global plugins from /Users/jimka/.sbt/1.0/plugins
[info] Loading project definition from /Users/jimka/Repos/regular-type-expression/cl-robdd-scala/project
[info] Loading settings for project cl-robdd-scala from build.sbt ...
[info] Set current project to cl-robdd-scala (in build file:/Users/jimka/Repos/regular-type-expression/cl-robdd-scala/)
[info] Compiling 29 Scala sources to /Users/jimka/Repos/regular-type-expression/cl-robdd-scala/target/scala-2.12/classes ...
[warn] /Users/jimka/Repos/regular-type-expression/cl-robdd-scala/src/main/scala/dfa/Dfa.scala:20:55: abstract type pattern L is unchecked since it is eliminated by erasure
[warn] require(protoDelta.forall { case (from: Int, label: L, to: Int) => Qids.contains(from) && Qids.contains(to) })
[warn] ^
[warn] /Users/jimka/Repos/regular-type-expression/cl-robdd-scala/src/main/scala/treereduce/ListSpecificTreeReduce.scala:44:51: abstract type pattern A is unchecked since it is eliminated by erasure
[warn] val reduced: List[A] = li.map { case (b1: A, b2: A) => f(b1, b2) }
[warn] ^
[warn] /Users/jimka/Repos/regular-type-expression/cl-robdd-scala/src/main/scala/treereduce/ListSpecificTreeReduce.scala:44:58: abstract type pattern A is unchecked since it is eliminated by erasure
[warn] val reduced: List[A] = li.map { case (b1: A, b2: A) => f(b1, b2) }
[warn] ^
[error] ## Exception when compiling 29 sources to /Users/jimka/Repos/regular-type-expression/cl-robdd-scala/target/scala-2.12/classes
[error] java.io.IOError: java.lang.RuntimeException: /packages cannot be represented as URI
[error] java.base/jdk.internal.jrtfs.JrtPath.toUri(JrtPath.java:176)
[error] scala.tools.nsc.classpath.JrtClassPath.asURLs(DirectoryClassPath.scala:213)
[error] scala.tools.nsc.classpath.AggregateClassPath.$anonfun$asURLs$1(AggregateClassPath.scala:64)
[error] scala.collection.TraversableLike.$anonfun$flatMap$1(TraversableLike.scala:244)
[error] scala.collection.Iterator.foreach(Iterator.scala:941)
[error] scala.collection.Iterator.foreach$(Iterator.scala:941)
[error] scala.collection.AbstractIterator.foreach(Iterator.scala:1429)
[error] scala.collection.IterableLike.foreach(IterableLike.scala:74)
[error] scala.collection.IterableLike.foreach$(IterableLike.scala:73)
[error] scala.collection.AbstractIterable.foreach(Iterable.scala:56)
[error] scala.collection.TraversableLike.flatMap(TraversableLike.scala:244)
[error] scala.collection.TraversableLike.flatMap$(TraversableLike.scala:241)
[error] scala.collection.AbstractTraversable.flatMap(Traversable.scala:108)
[error] scala.tools.nsc.classpath.AggregateClassPath.asURLs(AggregateClassPath.scala:64)
This is a serious warning that should also be visible in IntelliJ. Type patterns always match type variables, and you can easily introduce unsoundness to your program by doing this.
@ def unsound[A](as: List[Any]): List[A] = as.map { case a: A => a }
cmd2.sc:1: abstract type pattern A is unchecked since it is eliminated by erasure
def unsound[A](as: List[Any]): List[A] = as.map { case a: A => a }
^
defined function unsound
@ val wat = unsound[Int](List(true, "hello", 1.23))
wat: List[Int] = List(true, "hello", 1.23)
@ wat.map(_ + 1)
java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.Integer
scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:99)
scala.runtime.java8.JFunction1$mcII$sp.apply(JFunction1$mcII$sp.scala:17)
scala.collection.immutable.List.map(List.scala:219)
...
When I check in my system preferences it seems Java 8 is installed, but when I type java -version at the command line it tells me java 14 is installed. I’ve tried several times to re-install java 8 or java 11, and the command line java from /usr/bin/java always reports java 14. Is that a problem?
Do you know how sbt decides which version of scala to use? As I understand there’s no guarantee that intelliJ and sbt will chose the same version of scala. Right?
Am I correct that it is scala which choses the java version, or is it just the one installed in /usr/bin ?
sbt uses a hardwired Scala version internally (2.12.7 so far, as I understand from the discussion in the bug report), and for your project it uses whatever it has configured. IntelliJ should use the Scala version you have configured in sbt for your project, as well.
I’d guess that both sbt and IntelliJ use the java executable they find on the path - maybe it’s also configurable via cmd line args or env vars (JAVA_HOME), never looked into this.
The easiest remedy probably is to use JDK 11 (which doesn’t seem to be affected and is the current LTS version) and the latest stable sbt version.