Skip to content

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

Description

@vpavkin

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]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions