doobie icon indicating copy to clipboard operation
doobie copied to clipboard

New type derivation not working on list types

Open kuzkdmy opened this issue 3 years ago • 1 comments

Read not derived, next code results in such error

Cannot find or construct a Read instance for type: com.test.Main.DataWrapper2 But derivation works with simple Read[NewTypeWrapper]

package com.test

import doobie._
import doobie.postgres.implicits._
import io.estatico.newtype.macros.newtype

object Main extends App {
  @newtype case class NewTypeWrapper(value: Int)
  object NewTypeWrapper {
    implicit val read: Read[NewTypeWrapper] = Read[Int].map(NewTypeWrapper(_))
  }
  case class DataWrapper(one: NewTypeWrapper)
  case class DataWrapper1(list: List[Int])
  case class DataWrapper2(list: List[NewTypeWrapper])

  val t = NewTypeWrapper(1)
  println(Read[NewTypeWrapper])
  println(Read[DataWrapper])
  println(Read[DataWrapper1])
  println(Read[DataWrapper2])
}

kuzkdmy avatar Oct 10 '21 16:10 kuzkdmy

May be solution described here https://github.com/tpolecat/doobie/issues/691

kuzkdmy avatar Oct 12 '21 09:10 kuzkdmy