typelevel / simulacrum

First class syntax support for type classes in Scala
BSD 3-Clause "New" or "Revised" License
935 stars 61 forks source link

Compilation fails when updating from cats 2.2.0 to 2.3.0 #221

Closed cjllanwarne closed 3 years ago

cjllanwarne commented 3 years ago

We recently tried[0][1] to update from cats 2.2.0 to 2.3.0 but the following error starting being reported on our typeclasses:

Eg on our `AstNodeToTypeElement class (trying to import from our WdlWriter typeclass):

Error:(8, 48) value ops is not a member of object wdl.transforms.base.wdlom2wdl.WdlWriter
import wdl.transforms.base.wdlom2wdl.WdlWriter.ops._

Reverting the cats version back to 2.2.0 resolves these compilation errors.

mpilquist commented 3 years ago

Cats no longer uses simulacrum and instead auto-generates typeclass syntax via https://github.com/typelevel/simulacrum-scalafix. I'm guessing that the upgrade to cats 2.3.0 pulled in the simulacrum-scalafix-annotation jar dependency, which has its own no-op definitions of the simulacrum annotations: https://github.com/typelevel/simulacrum-scalafix/blob/master/annotation/src/main/scala/org/typelevel/simulacrum/package.scala

You can probably work around this by either excluding the simulacrum-scalafix-annotation dependency or ensuring the simulacrum jar is ahead of it on the classpath.

cc @djspiewak

cjllanwarne commented 3 years ago

Hi @mpilquist, thanks for responding so quickly!

I tried updating our dependencies to exclude simulacrum-scalafix but this didn't seem to make any difference. Am I doing this part wrong?

    "org.typelevel" %% "cats-core" % catsV
      exclude("org.typelevel", "simulacrum-scalafix"),
    "org.typelevel" %% "alleycats-core" % catsV
      exclude("org.typelevel", "simulacrum-scalafix"),
mpilquist commented 3 years ago

Try changing the artifact id to "simulacrum-scalafix-annotations_2.13"

cjllanwarne commented 3 years ago

So I tried switching to exclude that artifact ID:

    "org.typelevel" %% "cats-core" % catsV
      exclude("org.typelevel", "simulacrum-scalafix-annotations_2.13"),
    "org.typelevel" %% "alleycats-core" % catsV
      exclude("org.typelevel", "simulacrum-scalafix-annotations_2.13"),

And then just for good measure included a couple of others excludes as well:

    "org.typelevel" %% "cats-core" % catsV
      exclude("org.typelevel", "simulacrum-scalafix")
      exclude("org.typelevel", "simulacrum-scalafix-annotation")
      exclude("org.typelevel", "simulacrum-scalafix-annotations_2.13"),
    "org.typelevel" %% "alleycats-core" % catsV
      exclude("org.typelevel", "simulacrum-scalafix")
      exclude("org.typelevel", "simulacrum-scalafix-annotation")
      exclude("org.typelevel", "simulacrum-scalafix-annotations_2.13"),

Unfortunately, neither of these attempts managed to resolve the compilation issue

mpilquist commented 3 years ago

Can you run dependencyTree and look for simulacrum dependencies, either simulacrum proper or the scalafix ones and share result here?

cjllanwarne commented 3 years ago

That seems to have worked, thanks! Running dependencyTree identified the following imports which used the simulacrum-scalafix-annotations:

I also noticed that we're still on 2.12 so liberally excluded both _2.13 and _2.12 versions of the artifacts against all of those imports. That seems to have worked - so thank you!

One thing I'm not sure about is why nothing broke the compilation until I changed the cats version to 2.3.0 even though those libraries were already specified in the Dependencies... but I'm not going to complain since this seems to have resolved the issue.

Thanks again!

cjllanwarne commented 3 years ago

One final comment in case anyone re-discovers this thread later. Despite compiling with the individual excludes, my sbt assembly was still not happy until I issued a global exclude of the simulacrum-scalafix-annotations_2.12 artifact in my settings via:

    excludeDependencies ++= List(
      "org.typelevel" % "simulacrum-scalafix-annotations_2.12",
      "org.typelevel" % "simulacrum-scalafix-annotations_2.13"
    )

This had the added benefit of being able to remove all of the individual exclude("org.typelevel", "simulacrum-scalafix-annotation") annotations against individual indirect importers of the artifact.

mpilquist commented 3 years ago

This should do the trick too:

excludeDependencies += "org.typelevel" %% "simulacrum-scalafix-annotations"
cjllanwarne commented 3 years ago

Thanks again @mpilquist !