Skip to content

Commit

Permalink
lol
Browse files Browse the repository at this point in the history
  • Loading branch information
jatcwang committed Sep 10, 2024
1 parent 28594e5 commit 85d9e0f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 26 deletions.
12 changes: 4 additions & 8 deletions modules/core/src/main/scala-2/doobie/util/GetPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
package doobie.util

import shapeless._
import shapeless.ops.hlist.IsHCons

trait GetPlatform {
import doobie.util.compat.=:=

/** @group Instances */
implicit def unaryProductGet[A, L <: HList, H, T <: HList](
implicit def unaryProductGet[A, L <: HList, H](
implicit
G: Generic.Aux[A, L],
C: IsHCons.Aux[L, H, T],
H: Lazy[Get[H]],
E: (H :: HNil) =:= L
E: (H :: HNil) =:= L,
H: Lazy[Get[H]]
): MkGet[A] = {
void(C) // C drives inference but is not used directly
val get = H.value.tmap[A](h => G.from(h :: HNil))
val get = H.value.tmap[A](h => G.from(E.apply(h :: HNil)))
MkGet.lift(get)
}

Expand Down
12 changes: 4 additions & 8 deletions modules/core/src/main/scala-2/doobie/util/PutPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
package doobie.util

import shapeless._
import shapeless.ops.hlist.IsHCons

trait PutPlatform {
import doobie.util.compat.=:=

/** @group Instances */
implicit def unaryProductPut[A, L <: HList, H, T <: HList](
implicit def unaryProductPut[A, H, L <: HList](
implicit
G: Generic.Aux[A, L],
C: IsHCons.Aux[L, H, T],
H: Lazy[Put[H]],
E: (H :: HNil) =:= L
E: L =:= (H :: HNil),
H: Lazy[Put[H]]
): MkPut[A] = {
void(E) // E is a necessary constraint but isn't used directly
val put = H.value.contramap[A](a => G.to(a).head)
val put = H.value.contramap[A](a => E.apply(G.to(a)).head)
MkPut.lift(put)
}

Expand Down
15 changes: 5 additions & 10 deletions modules/core/src/test/scala-2/doobie/util/PutSuitePlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,26 @@

package doobie.util
import doobie.testutils.{VoidExtensions, assertContains}
import doobie.testutils.TestClasses.CCAnyVal

object PutSuitePlatform {
final case class Y(x: String) extends AnyVal
final case class P(x: Int) extends AnyVal
}
object PutSuitePlatform {}

trait PutSuitePlatform { self: munit.FunSuite =>
import PutSuitePlatform._

test("Put can be auto derived for unary products (AnyVal)") {
import doobie.generic.auto._

Put[Y].void
Put[P].void
Put[CCAnyVal].void
}

test("Put can be explicitly derived for unary products (AnyVal)") {
Put.derived[Y].void
Put.derived[P].void
Put.derived[CCAnyVal].void
}

test("Put should not be derived for non-unary products") {
import doobie.generic.auto._
import doobie.testutils.TestClasses.{CCIntString, PlainObj}

println(compileErrors("Put[CCIntString]"))
assertContains(compileErrors("Put[CCIntString]"), "implicit value")
assertContains(compileErrors("Put[(Int, Int)]"), "implicit value")
assertContains(compileErrors("Put[PlainObj.type]"), "implicit value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ object TestClasses {

case class CCIntString(i: Int, s: String)

case class CCAnyVal(s: String) extends AnyVal

object PlainObj
}

0 comments on commit 85d9e0f

Please sign in to comment.