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

match might not be exhaustive #150

Open
ghostbuster91 opened this issue May 23, 2021 · 0 comments
Open

match might not be exhaustive #150

ghostbuster91 opened this issue May 23, 2021 · 0 comments

Comments

@ghostbuster91
Copy link

ghostbuster91 commented May 23, 2021

Hi,

I am not sure whether it is a bug, but for sure it's quite a surprising behavior.

There is an option in the configuration called Configuration.default.withDefaults which allows for the derivation of non-case classes based on the fields they specify.

When combined with the following scalac options:-Xlint:strict-unsealed-patmat and -Wconf:cat=other-match-analysis:error it causes compilation to fail with "match may not be exhaustive" error.

This alone isn't yet that bad, but the error will propagate downstream through the chain of defined derivations and macros making it quite hard to debug for the end-users. I myself got it when I was trying to derive some tapir's type-classes that rely on circe codecs.

Here is a failed build on CI which illustrates that problem: https://github.com/softwaremill/livestub/runs/2586343239

Update: When trying to prepare a minimal example to reproduce I discovered that such a class needs also to specify an unapply method.

The minimal example to reproduce:

import io.circe.generic.extras.Configuration
import io.circe.generic.semiauto._

trait JsonSupport {
  implicit val config: Configuration = Configuration.default.withDefaults

  implicit val headerEncoder = deriveEncoder[Header]
}

class Header(val name: String, val value: String) {}

object Header {
  def unapply(h: Header): Option[(String, String)] = Some((h.name, h.value))

}

Originally reported in circe/circe#1756

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

1 participant