evolution-gaming / derivation

Configured derivation library for scala 3
MIT License
34 stars 6 forks source link

Problems with deriving EvoCodec for ADT's #26

Open kpodsiad opened 2 years ago

kpodsiad commented 2 years ago

Error messages suggests problem with LazySummon

Base Snippet:

//> using scala "3.2.0"
//> using lib "com.evolution::derivation-circe:0.1-fd8fba2a1f9529f0adc55912129fe9a6974918fc-SNAPSHOT"

import evo.derivation.*
import evo.derivation.circe.*
import evo.derivation.config.Config
import io.circe.Codec

sealed trait MyDataType
final case class Foo(foo: String, bar: Int) extends MyDataType
case object Baz extends MyDataType

Compiling

object MyDataType:
  implicit val config: Config[MyDataType] = Config.derived[MyDataType]
  implicit val actionCodec: Codec[MyDataType] =
    EvoCodec.derived[MyDataType]
object MyDataType:
  given Config[MyDataType] = Config.derived[MyDataType]
  implicit val actionCodec: Codec[MyDataType] =
    EvoCodec.derived[MyDataType]

Not compiling

object MyDataType:
  implicit val actionCodec: Codec[MyDataType] =
    EvoCodec.derived[MyDataType](using Config.derived[MyDataType]) 
object MyDataType:
  val config: Config[MyDataType] = Config.derived[MyDataType]
  implicit val actionCodec: Codec[MyDataType] =
    EvoCodec.derived[MyDataType](using config) 
Odomontois commented 2 years ago

Yes, currently derivation for constructors requires that there is given Confif for the top enumeration. We can try to change LazySummon mechanics a little bit if this is a problem

kpodsiad commented 2 years ago

I didn't look through LazySummon code but if config is passed as an implicit parameter via using clause then this shouldn't be enough?