Skip to content

Commit 1711734

Browse files
committed
Fix duplicate doobie/util/package.scala for Scala 3
1 parent 5d37601 commit 1711734

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

modules/core/src/main/scala-3/doobie/util/GetPlatform.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package doobie.util
77
import scala.deriving.Mirror
88
import scala.compiletime.constValue
99
import scala.reflect.Enum
10+
import doobie.util.derivation.{summonSingletonCases, summonLabels}
1011

1112
trait GetPlatform {
1213
private def of[A](name: String, cases: List[A], labels: List[String]): Get[A] =

modules/core/src/main/scala-3/doobie/util/PutPlatform.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package doobie.util
77
import scala.compiletime.constValue
88
import scala.deriving.Mirror
99
import scala.reflect.Enum
10+
import doobie.util.derivation.{summonSingletonCases, summonLabels}
1011

1112
trait PutPlatform {
1213
inline final def deriveEnumString[A <: Enum](using mirror: Mirror.SumOf[A]): Put[A] =
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2013-2020 Rob Norris and Contributors
2+
// This software is licensed under the MIT License (MIT).
3+
// For more information see LICENSE or https://opensource.org/licenses/MIT
4+
5+
package doobie.util
6+
7+
import scala.compiletime.{constValue, erasedValue, error, summonInline}
8+
import scala.deriving.Mirror
9+
10+
private[util] object derivation:
11+
12+
inline final def summonLabels[T <: Tuple]: List[String] =
13+
inline erasedValue[T] match
14+
case _: EmptyTuple => Nil
15+
case _: (t *: ts) => constValue[t].asInstanceOf[String] :: summonLabels[ts]
16+
17+
inline final def summonSingletonCases[T <: Tuple, A](inline typeName: String): List[A] =
18+
inline erasedValue[T] match
19+
case _: EmptyTuple => Nil
20+
case _: (h *: t) =>
21+
inline summonInline[Mirror.Of[h]] match
22+
case m: Mirror.Singleton => m.fromProduct(EmptyTuple).asInstanceOf[A] :: summonSingletonCases[t, A](typeName)
23+
case m: Mirror =>
24+
error("Enum " + typeName + " contains non singleton case " + constValue[m.MirroredLabel])

modules/core/src/main/scala-3/doobie/util/package.scala

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)