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

extras.semiauto.deriveEnumerationEncoder not work with 'val' field overridden #792

Closed
cwei-bgl opened this issue Dec 6, 2017 · 2 comments
Milestone

Comments

@cwei-bgl
Copy link

cwei-bgl commented Dec 6, 2017

Hi, there is an error when I used 'val' field overridden below. I am using circle 0.9.0-M2.

sealed trait SuperType {
def name: String
}
object SuperType {
object SubType1 extends SuperType {
override def name: String = "type1"
//override val name: String = "type1" //not work when using 'val'
}
object SubType2 extends SuperType {
override def name: String = "type2"
//override val name: String = "type2" //not work when using 'val'
}
}

implicit val superTypeEncoder = deriveEnumerationEncoder[SuperType]

I can get around it by using 'def' instead of 'val' at the moment. Thanks.

Cheng

@travisbrown travisbrown added this to the 0.9.0 milestone Dec 6, 2017
@travisbrown travisbrown added the bug label Dec 6, 2017
@travisbrown
Copy link
Member

Thanks for the report!

@travisbrown travisbrown modified the milestones: 0.9.0, 0.10.0 Jan 1, 2018
@travisbrown travisbrown added won't fix and removed bug labels Jun 11, 2019
@travisbrown
Copy link
Member

The problem here is that all of circe-generic is built on Shapeless's LabelledGeneric instances, and Shapeless does not provide instances when the val is present:

sealed trait SuperType { def name: String }
object SuperType {
   object SubType1 extends SuperType { def name: String = "type1" }
   object SubType2 extends SuperType { val name: String = "type2" }
}

And then:

scala> shapeless.LabelledGeneric[SuperType.SubType1.type]
res0: shapeless.LabelledGeneric[SuperType.SubType1.type]{type Repr = shapeless.HNil} = shapeless.LabelledGeneric$$anon$1@3e8417fb

scala> shapeless.LabelledGeneric[SuperType.SubType2.type]
<console>:28: error: could not find implicit value for parameter lgen: shapeless.LabelledGeneric[SuperType.SubType2.type]
       shapeless.LabelledGeneric[SuperType.SubType2.type]
                                ^

You might want to open an issue about this on the Shapeless side, and if Shapeless ever starts providing instances in these cases, everything should just work on the circe side.

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

No branches or pull requests

2 participants