Skip to content
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

Automatic derivation with private implicits, "-Ywarn-unused" and Scala 2.12.4 produces erroneous warnings #769

Closed
migesok opened this issue Oct 23, 2017 · 3 comments

Comments

@migesok
Copy link

migesok commented Oct 23, 2017

Hi!
I discovered an issue after migration to Scala 2.12.4. It is possibly a bug in scalac but I'm not sure.
Here's minimal example:
From build.sbt:

scalaVersion := "2.12.4"
scalacOptions ++= Seq("-Ywarn-unused", "-Xfatal-warnings")
val circeVersion = "0.8.0"
libraryDependencies ++= Seq(
  "io.circe" %% "circe-core",
  "io.circe" %% "circe-generic",
  "io.circe" %% "circe-parser"
).map(_ % circeVersion)

Test.scala:

object Test extends App {
  import java.time.Instant
  import io.circe.generic.auto._
  import io.circe.syntax._
  
  private implicit val instantEncoder: io.circe.Encoder[Instant] =
    io.circe.Encoder.encodeLong.contramap(_.toEpochMilli)

  case class A(prop: Instant)

  println(A(Instant.now()).asJson)
}

Like this it fails to compile:

private val instantEncoder in object Test is never used

If you comment out instantEncoder it fails also:

could not find implicit value for parameter encoder: io.circe.Encoder[Test.A]

And it compiles fine with Scala 2.12.3.

@thatfulvioguy
Copy link

I've also ran into this issue.

This can be worked around in the meantime by annotating the offending declaration with silent or by change its visibility from private to private[NameOfEnclosingType].

@javierarrieta
Copy link

javierarrieta commented Nov 14, 2017

We are also running into this issue, would love to help but don't know even where to start looking

We are running into that issue for an implicit parameter, don't want to introduce silent for this tbh

  implicit def dataChangeEventEncoder[T](implicit enc: Encoder[T]) = semiauto.deriveEncoder[DataChangeEvent[T]]

@pdo400
Copy link

pdo400 commented Jan 8, 2018

Any info on this or a link to somewhere where there is more discussion?

Edit: Just found these issues:
scala/bug#10599
scala/bug#10571

TL;DR: Use the compiler flag -Ywarn-macros:after

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants