New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@JsonCodec produces warnings on generic case class with -Wunused:params #1411
Comments
This is a bug in the compiler, which you can reproduce without the macro annotation: import io.circe.Decoder
import io.circe.generic.semiauto.deriveDecoder
case class Foo[A](data: A)
object Foo {
implicit def decodeFoo[A](implicit decode0: Decoder[A]): Decoder[Foo[A]] =
deriveDecoder[Foo[A]]
} …which gives: // Exiting paste mode, now interpreting.
implicit def decodeFoo[A](implicit decode0: Decoder[A]): Decoder[Foo[A]] =
^
On line 7: warning: parameter value decode0 in method decodeFoo is never used
The If someone knows a workaround here, I'd be happy to hear about it, but I hate these macro annotations and am looking forward to the day they'll be gone, so I'm inclined to close this as out-of-scope for Circe. Thanks for the report, though, @oleg-py—I've seen questions about this before, but I don't think we had a proper issue. |
The common thing to do with unused implicits is just object Foo {
implicit def decodeFoo[A](implicit decode0: Decoder[A]): Decoder[Foo[A]] = {
val _ = decode0
deriveDecoder[Foo[A]]
}
} thought that won't scale with number of type parameters. You can also have a helper unused function instead: object Foo {
implicit def decodeFoo[A](implicit decode0: Decoder[A]): Decoder[Foo[A]] = {
io.circe.util.unused(decode0)
deriveDecoder[Foo[A]]
}
} That of course has the drawback of polluting the library. The third way I know of - not sure if it's supported by current Scala macros, but I've used it in better-monadic-for - is to mark methods and/or implicit parameters as synthetic and/or artifact (I don't know the difference except that they both work to silence many warnings). |
I only started getting this now on scala 2.13.5. Did something change? |
2.13.5 has added linting for unused context bounds (this pull). |
The same seems to happen with |
This is a compiler issue, not circe. |
Did anybody report this to the scala developers? |
circe 0.13.0
Annotating a generic case class with
@JsonCodec
:Produces warnings:
Scastie: https://scastie.scala-lang.org/bGI7rDGURBWynQNaajI6vg
The text was updated successfully, but these errors were encountered: