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

Derivation for generic case classes fails with additional context bounds #13

Open
vpavkin opened this issue Jun 8, 2017 · 5 comments
Open

Comments

@vpavkin
Copy link

vpavkin commented Jun 8, 2017

Hi!
Found this issue while trying out circe-derivation 0.8.0-M2:

import io.circe.{Decoder, Encoder}
import io.circe.derivation._

trait Typeclass[T]

// notice additional context bound here
case class Test1[T: Typeclass](v: T)
case class Test2[T](v: T)

object CirceDerivation {
  // we have to pass the bound here.
  implicit def encT1[T: Typeclass : Encoder]: Encoder[Test1[T]] = deriveEncoder[Test1[T]]
  implicit def decT1[T: Typeclass : Decoder]: Decoder[Test1[T]] = deriveDecoder[Test1[T]]

  implicit def encT2[T : Encoder]: Encoder[Test2[T]] = deriveEncoder[Test2[T]]
  implicit def decT2[T : Decoder]: Decoder[Test2[T]] = deriveDecoder[Test2[T]]
}

For Test2 all good.
For Test1 derivation fails with this (for both encoder and decoder):

exception during macro expansion:
[error] scala.ScalaReflectionException: value evidence$1 is not a method
[error] 	at scala.reflect.api.Symbols$SymbolApi.asMethod(Symbols.scala:228)
[error] 	at scala.reflect.api.Symbols$SymbolApi.asMethod$(Symbols.scala:222)
[error] 	at scala.reflect.internal.Symbols$SymbolContextApiImpl.asMethod(Symbols.scala:88)
[error] 	at io.circe.derivation.DerivationMacros$$anonfun$membersFromPrimaryConstr$1.$anonfun$applyOrElse$1(DerivationMacros.scala:45)
[error] 	at scala.collection.immutable.List.map(List.scala:287)
[error] 	at io.circe.derivation.DerivationMacros$$anonfun$membersFromPrimaryConstr$1.applyOrElse(DerivationMacros.scala:44)
[error] 	at io.circe.derivation.DerivationMacros$$anonfun$membersFromPrimaryConstr$1.applyOrElse(DerivationMacros.scala:43)
[error] 	at scala.collection.TraversableOnce.collectFirst(TraversableOnce.scala:145)
[error] 	at scala.collection.TraversableOnce.collectFirst$(TraversableOnce.scala:132)
[error] 	at scala.reflect.internal.Scopes$Scope.collectFirst(Scopes.scala:51)
[error] 	at io.circe.derivation.DerivationMacros.membersFromPrimaryConstr(DerivationMacros.scala:43)
[error] 	at io.circe.derivation.DerivationMacros.productRepr(DerivationMacros.scala:52)
[error] 	at io.circe.derivation.DerivationMacros.materializeEncoderImpl(DerivationMacros.scala:221)
[error] 	at io.circe.derivation.DerivationMacros.materializeEncoder(DerivationMacros.scala:87)
[error]   implicit def encT1[T: Typeclass : Encoder]: Encoder[Test1[T]] = deriveEncoder[Test1[T]]
@vpavkin
Copy link
Author

vpavkin commented Jun 8, 2017

ordering of context bounds does not matter: macro fails anyway.

@travisbrown
Copy link
Member

travisbrown commented Jun 8, 2017

@vpavkin Good catch, thanks for reporting! I'll take a look.

@hibikir
Copy link

hibikir commented Apr 25, 2018

@travisbrown This issue is still alive in 0.9.0-M3, right? For the time being I have to keep a semiauto usage because the class in question has a [T : ClassTag] bound.

@aukgit
Copy link

aukgit commented May 6, 2020

ordering of context bounds does not matter: macro fails anyway.

Will you please kindly elaborate this a bit more for understanding purposes?

Note: I am new to scala.

@mikla
Copy link

mikla commented Feb 13, 2021

Is there a hope that it can be fixed someday?

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