Why is my scan test not compiling? (scala.MatchError)

My project has all the code:

package fileSearcher import org.scalatest.FlatSpec class FilterCheckerTests extends org.scalatest.FlatSpec { "Foo" should "not do terrible things" in { assert(1 == 1) } } 

Eclipse

Sbt error with scala.MatchError error (see below for more details).

What am I doing wrong?

 [info] Compiling 1 Scala source to C:\scala\course\FileSearcher\target\scala-2.1 0\test-classes... [error] [error] while compiling: C:\scala\course\FileSearcher\src\test\scala\fileSe archer\FilterCheckerTests.scala [error] during phase: typer [error] library version: version 2.10.4 [error] compiler version: version 2.10.4 [error] reconstructed args: -classpath C:\scala\course\FileSearcher\target\sca la-2.10\test-classes;C:\scala\course\FileSearcher\target\scala-2.10\classes;C:\U sers\Max\.ivy2\cache\org.scalatest\scalatest_2.11\bundles\scalatest_2.11-2.2.4.j ar;C:\Users\Max\.ivy2\cache\org.scala-lang\scala-reflect\jars\scala-reflect-2.11 .2.jar;C:\Users\Max\.ivy2\cache\org.scala-lang.modules\scala-xml_2.11\bundles\sc ala-xml_2.11-1.0.2.jar;C:\Users\Max\.ivy2\cache\com.novocode\junit-interface\jar s\junit-interface-0.11.jar;C:\Users\Max\.ivy2\cache\junit\junit\jars\junit-4.11. jar;C:\Users\Max\.ivy2\cache\org.hamcrest\hamcrest-core\jars\hamcrest-core-1.3.j ar;C:\Users\Max\.ivy2\cache\org.scala-sbt\test-interface\jars\test-interface-1.0 .jar -bootclasspath C:\Program Files\Java\jdk1.8.0_20\jre\lib\resources.jar;C:\P rogram Files\Java\jdk1.8.0_20\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_20\j re\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.8.0_20\jre\lib\jsse.jar;C:\Prog ram Files\Java\jdk1.8.0_20\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_20\jre \lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_20\jre\lib\jfr.jar;C:\Program F iles\Java\jdk1.8.0_20\jre\classes;C:\Users\Max\.ivy2\cache\org.scala-lang\scala- library\jars\scala-library-2.10.4.jar [error] [error] last tree to typer: Literal(Constant(true)) [error] symbol: null [error] symbol definition: null [error] tpe: Boolean(true) [error] symbol owners: [error] context owners: value <local FilterCheckerTests> -> class FilterCh eckerTests -> package fileSearcher [error] [error] == Enclosing template or block == [error] [error] Template( // val <local FilterCheckerTests>: <notype> in class FilterChe ckerTests [error] "org.scalatest.FlatSpec" // parents [error] ValDef( [error] private [error] "_" [error] <tpt> [error] <empty> [error] ) [error] // 2 statements [error] DefDef( // def <init>(): fileSearcher.FilterCheckerTests in class Filt erCheckerTests [error] <method> [error] "<init>" [error] [] [error] List(Nil) [error] <tpt> // tree.tpe=fileSearcher.FilterCheckerTests [error] Block( // tree.tpe=Unit [error] Apply( // def <init>(): org.scalatest.FlatSpec in class FlatSpec, tree.tpe=org.scalatest.FlatSpec [error] FilterCheckerTests.super."<init>" // def <init>(): org.scalatest .FlatSpec in class FlatSpec, tree.tpe=()org.scalatest.FlatSpec [error] Nil [error] ) [error] () [error] ) [error] ) [error] Apply( [error] "Foo".should("not do terrible things")."in" [error] Apply( [error] "assert" [error] Apply( // def ==(x: Int): Boolean in class Int, tree.tpe=Boolean(t rue) [error] 1."$eq$eq" // def ==(x: Int): Boolean in class Int, tree.tpe=(x: Int)Boolean [error] 1 [error] ) [error] ) [error] ) [error] ) [error] [error] == Expanded type of tree == [error] [error] ConstantType(value = Constant(true)) [error] [error] uncaught exception during compilation: scala.MatchError [trace] Stack trace suppressed: run last test:compile for the full output. [error] (test:compile) scala.MatchError: false (of class scala.reflect.internal. Trees$Literal) [error] Total time: 0 s, completed Jun 20, 2015 11:07:15 AM 1. Waiting for source changes... (press enter to interrupt) 
+5
source share
2 answers

As you can see, looking at the class path printed by the compiler, you mixed Scala 2.10 with libraries for 2.11. Given that major versions of Scala are not binary compatible, this will never work.

This can be fixed using scalaVersion := "2.11.5" or by setting all the dependencies to use versions 2.10, which can be done using libraryDependencies += "group" %% "libName" % "version" , where %% means that sbt automatically uses the correct version of the library.

+10
source

For those who get a similar error (like me) that runs Scala 2.10 using Maven instead of sbt, the solution is simply to change the Maven dependency proposed on the ScalaTest website from

 <dependency> <groupId>org.scalatest</groupId> <artifactId>scalatest_2.11</artifactId> <version>3.0.0</version> <scope>test</scope> </dependency> 

to

 <dependency> <groupId>org.scalatest</groupId> <artifactId>scalatest_2.10</artifactId> <version>3.0.0</version> <scope>test</scope> </dependency> 
+2
source

All Articles