ghik / silencer

Scala compiler plugin for warning suppression
Apache License 2.0
255 stars 33 forks source link

Using scala-collection-compat together with silencer-plugin is broken #63

Closed sideeffffect closed 3 years ago

sideeffffect commented 3 years ago

When the scala-collection-compat library is used together with the silencer-plugin compiler plugin, you get errors like this:

[error] /home/runner/work/izumi-reflect/izumi-reflect/izumi-reflect/izumi-reflect/src/main/scala/izumi/reflect/internal/fundamentals/collections/IzMappings.scala:26:4: expected literal string as @nowarn annotation argument
[error]   @nowarn("msg=deprecated")
[error]    ^

Workaround is to drop silencer-plugin, but that might not be the desired solution.

It's worth to note that scala-collection-compat defines its own nowarn annotation: https://github.com/scala/scala-collection-compat/blob/master/compat/src/main/scala-2.11_2.12/scala/annotation/nowarn.scala

Related: https://github.com/zio/izumi-reflect/pull/121 https://github.com/scala/scala-collection-compat/issues/413#issuecomment-767967951 https://github.com/scala/scala-collection-compat/pull/417

/cc @SethTisue @ekrich

continuation of https://github.com/scala/scala-collection-compat/issues/418

ghik commented 3 years ago

What Scala version is this?

sideeffffect commented 3 years ago

2.11.12, I think. When we upgraded izumi-reflect Scala Native 0.4.0, we also had to upgrade to scala-collection-compat to 2.4.0. We had to remove silencer in order to make the build pass: https://github.com/zio/izumi-reflect/pull/121

Trying to add it back is still causing these issues: https://github.com/zio/izumi-reflect/pull/128

rdesgroppes commented 3 years ago

I faced the very same problem when trying to bump scala-collection-compat version from 2.3.2 up to 2.4.0, then to 2.4.1. It seems related to this recently introduced change, make @nowarn a ClassfileAnnotation, as in 2.12.13: https://github.com/scala/scala-collection-compat/commit/86475b4cb540f81723d6b09753355aff75c149e3#diff-6d5efe0f0fcfb13692e6abe75577291796099973c93b40ffe8e8bed7db0ea5c6

sideeffffect commented 3 years ago

@ghik are you planing on making a release soon?

ghik commented 3 years ago

@sideeffffect there should be 1.7.2 soon, see https://github.com/ghik/silencer/actions

sideeffffect commented 3 years ago

For the record, it solves the issue we had in izumi-reflect https://github.com/zio/izumi-reflect/pull/128 Many thanks :smiley:

rdesgroppes commented 3 years ago

there should be 1.7.2 soon, see https://github.com/ghik/silencer/actions

I see the plugin got published for Scala 2.12.13, but not for other versions. @ghik, is that intentional?

ghik commented 3 years ago

@rdesgroppes mvnrepository.com seems to be out of sync, search.maven.org shows other versions

rdesgroppes commented 3 years ago

Thanks, @ghik, I indeed see more Scala versions there: https://search.maven.org/search?q=g:com.github.ghik%20AND%20a:silencer-plugin_*%20AND%20v:1.7.2 ... unfortunately even recent versions of sbt (1.4.7) still use the Scala 2.12.12 compiler and therefore don't find the corresponding compilerPlugin("com.github.ghik" % "silencer-plugin" % "1.7.2" cross CrossVersion.full)...

ghik commented 3 years ago

@rdesgroppes yes, I don't cover all minor Scala versions because that would be a cross-building nightmare considering all the minor changes that might be introduced into the compiler API with every minor Scala version. In this case, 2.12.13 broke compatibility of error reporting API with 2.12.12 so I decided to drop 2.12.12 and assumed users can bump their Scala version.

rdesgroppes commented 3 years ago

[...] I decided to drop 2.12.12 and assumed users can bump their Scala version.

@ghik Fair enough. But, since:

  1. as of today (Feb 3, 2021), there's no release of sbt based on a Scala 2.12.13 runtime,
  2. silencer-plugin 1.7.1 is incompatible with scala-collection-compat 2.4.0+.

... should a further note be added to https://github.com/ghik/silencer/blob/master/README.md#silencer-scala-compiler-plugin-for-warning-suppression so that sbt users stick to silencer-plugin 1.7.1 and scala-collection-compat 2.3.2?

ghik commented 3 years ago

@rdesgroppes Since you're bound by Scala version used by sbt, I'm assuming you are developing an sbt plugin? I'm not familiar with sbt plugin development but in principle you should be able to force 2.12.13 to be used in your plugin. This should work because minor Scala versions are supposed to be both backwards and forward compatible.