scalaintellij-ideascalatestscalactic

Why "could not find implicit" error in Scala + Intellij + ScalaTest + Scalactic but not from sbt


I have this code that is working 100% from sbt , executing sbt test but throw a compilation error in Intellij Idea.

import org.scalatest.{BeforeAndAfter, FunSuite, GivenWhenThen}

class SimpleTest extends FunSuite with GivenWhenThen with BeforeAndAfter {
  test("Simple Test") {
    Given("Why this error?")
    assert("ok" === "ok")
  }
}

The error is:

Error:(5, 10) could not find implicit value for parameter pos: org.scalactic.source.Position
    Given("Why this error?")
Error:(5, 10) not enough arguments for method Given: (implicit pos: org.scalactic.source.Position)Unit.
Unspecified value parameter pos.
    Given("Why this error?")
Error:(6, 11) could not find implicit value for parameter prettifier: org.scalactic.Prettifier
    assert("ok" === "ok")
Error:(6, 11) macro applications do not support named and/or default arguments
    assert("ok" === "ok")
Error:(6, 11) not enough arguments for macro method assert: (implicit prettifier: org.scalactic.Prettifier, implicit pos: org.scalactic.source.Position)org.scalatest.Assertion.
Unspecified value parameters prettifier, pos.
    assert("ok" === "ok")
Error:(4, 23) could not find implicit value for parameter pos: org.scalactic.source.Position
  test("Simple Test") {

After refresh and reload as suggested:

Error:(6, 11) exception during macro expansion: 
java.lang.NoSuchMethodError: org.scalactic.BooleanMacro.genMacro(Lscala/reflect/api/Exprs$Expr;Ljava/lang/String;Lscala/reflect/api/Exprs$Expr;)Lscala/reflect/api/Exprs$Expr;
    at org.scalatest.AssertionsMacro$.assert(AssertionsMacro.scala:34)
    assert("ok" === "ok")

I am using:

IntelliJ IDEA 2016.3.2
Build #IU-163.10154.41, built on December 21, 2016

scalaVersion := "2.11.0",
"org.scalactic" %% "scalactic" % "3.0.1" % "test",
"org.scalatest" %% "scalatest" % "3.0.1" % "test"

Notes: - Using File -> Invalidate Caches / Restart does not fix the problem - Example that reproduce the error: Example in Github


Solution

  • Workarounds at the bottom of the response. ;)

    This problem is related with this list of BUGs:

    The problem is that there are dependencies in the project that are using, using test scope, other versions of scalatest and scalactic.

    IntelliJ Idea is mixing compile scope and test scope, but SBT is working correctly. IntelliJ Idea team said in the BUG that they are working in this.

    My workaround, at the moment, has been move to the same older version that the other libraries are using for testing.

    Notes:

    @justin-kaeser is assigned and working to fix this. Thx!

    A lot of improvement related to the Scala plugin in that latest previews.

    Example to reproduce the error : https://github.com/angelcervera/idea-dependencies-bug

    Few Workarounds:

    1. Remove problematic dependencies from the Project structure -> Modules
    2. Exclude libraries in the sbt.
    3. Use the same version.
    4. Try with the last EAP: https://www.jetbrains.com/idea/nextversion/