jsoniter-scala icon indicating copy to clipboard operation
jsoniter-scala copied to clipboard

JsonCodecMaker fails in self-type scenario

Open nkgm opened this issue 1 year ago • 6 comments

Here's a simplified scenario. Any insight would be greatly appreciated.

import com.github.plokhotnyuk.jsoniter_scala.core.*
import com.github.plokhotnyuk.jsoniter_scala.macros.*

trait Aggregate {
  type Props

  def propsCodec: JsonValueCodec[Props]

  given JsonValueCodec[Props] = propsCodec
}

trait Events { self: Aggregate =>

  case class MyEvent(props: Props)

  // works here
  // val myEventCodec: JsonValueCodec[MyEvent] = JsonCodecMaker.make
}

object Person extends Aggregate with Events {

  case class Props(name: String, age: Int)

  val propsCodec: JsonValueCodec[Props] = JsonCodecMaker.make

  // No implicit 'com.github.plokhotnyuk.jsoniter_scala.core.JsonValueCodec[_ >: scala.Nothing <: scala.Any]' 
  // defined for 'Events.this.Props'.
  val myEventCodec: JsonValueCodec[MyEvent] = JsonCodecMaker.make
}

nkgm avatar Sep 04 '24 17:09 nkgm