Skip to content

Commit

Permalink
scala 3 compiles?
Browse files Browse the repository at this point in the history
  • Loading branch information
jatcwang committed Oct 27, 2024
1 parent a80a1a2 commit 3d4d831
Show file tree
Hide file tree
Showing 21 changed files with 102 additions and 72 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ lazy val weaverVersion = "0.8.4"
ThisBuild / tlBaseVersion := "1.0"
ThisBuild / tlCiReleaseBranches := Seq("main") // publish snapshots on `main`
ThisBuild / tlCiScalafmtCheck := true
ThisBuild / scalaVersion := scala212Version
//ThisBuild / scalaVersion := scala3Version
//ThisBuild / scalaVersion := scala212Version
ThisBuild / scalaVersion := scala3Version
ThisBuild / crossScalaVersions := Seq(scala212Version, scala213Version, scala3Version)
ThisBuild / developers += tlGitHubDev("tpolecat", "Rob Norris")
ThisBuild / tpolecatDefaultOptionsMode :=
Expand Down
14 changes: 7 additions & 7 deletions modules/core/src/main/scala-3/doobie/util/MkReadPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package doobie.util

import scala.deriving.Mirror
import doobie.util.shapeless.OrElse
import shapeless.OrElse

trait MkReadPlatform:

Expand All @@ -26,12 +25,13 @@ trait MkReadPlatform:
using H: Read[H] `OrElse` Derived[MkRead[H]]
): Derived[MkRead[H *: EmptyTuple]] = {
val headInstance = H.fold(identity, _.instance)
new Derived(new MkRead(
Read.Composite(
List(headInstance),
list => list(0).asInstanceOf[H] *: EmptyTuple
)
))
new Derived(
new MkRead(
Read.Composite(
List(headInstance),
list => list(0).asInstanceOf[H] *: EmptyTuple
)
))
}

// Derivation inductive case for tuples
Expand Down
27 changes: 17 additions & 10 deletions modules/core/src/main/scala-3/doobie/util/ReadPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@

package doobie.util

import scala.deriving.Mirror

trait ReadPlatform extends LowestPriorityRead:

// FIXME: needs to define both base case and inductive
given derivedTuple[P <: Tuple, A](

given tupleBase[H](
using H: Read[H]
): Read[H *: EmptyTuple] =
Read.Composite(
List(H),
list => list(0).asInstanceOf[H] *: EmptyTuple
)

given tuple[H, T <: Tuple](
using
m: Mirror.ProductOf[P],
i: A =:= m.MirroredElemTypes,
w: Read[A]
): Read[P] =
MkRead.derived[P, A]
H: Read[H],
T: Read[T]
): Read[H *: T] =
Read.Composite(
List(H, T),
list => list(0).asInstanceOf[H] *: list(1).asInstanceOf[T]
)
29 changes: 20 additions & 9 deletions modules/core/src/main/scala-3/doobie/util/WritePlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@

package doobie.util

import scala.deriving.Mirror

trait WritePlatform extends LowestPriorityWrite:

// FIXME: needs to define both base case and inductive
given derivedTuple[P <: Tuple, A](
given tupleBase[H](
using H: Write[H]
): Write[H *: EmptyTuple] =
Write.Composite[H *: EmptyTuple](
List(H),
{
case h *: EmptyTuple => List(h)
}
)

given tuple[H, T <: Tuple](
using
m: Mirror.ProductOf[P],
i: m.MirroredElemTypes =:= A,
w: Write[A]
): Write[P] =
MkWrite.derived[P, A]
H: Write[H],
T: Write[T]
): Write[H *: T] =
Write.Composite(
List(H, T),
{
case h *: t => List(h, t)
}
)
4 changes: 3 additions & 1 deletion modules/core/src/main/scala/doobie/util/read.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import doobie.free.resultset as IFRS
import java.sql.ResultSet
import scala.annotation.implicitNotFound

/*
@implicitNotFound("""
Cannot find or construct a Read instance for type:
Expand Down Expand Up @@ -44,6 +45,7 @@ and similarly with Get:
And find the missing instance and construct it as needed. Refer to Chapter 12
of the book of doobie for more information.
""")
*/
sealed trait Read[A] {
def unsafeGet(rs: ResultSet, startIdx: Int): A
def gets: List[(Get[?], NullabilityKnown)]
Expand Down Expand Up @@ -146,7 +148,7 @@ trait LowestPriorityRead {

final class MkRead[A](val underlying: Read[A]) extends Read[A] {
override def unsafeGet(rs: ResultSet, startIdx: Int): A = underlying.unsafeGet(rs, startIdx)
override def gets: List[(Get[_], NullabilityKnown)] = underlying.gets
override def gets: List[(Get[?], NullabilityKnown)] = underlying.gets
override def toOpt: Read[Option[A]] = underlying.toOpt
override def length: Int = underlying.length
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import doobie.testutils.TestClasses.{CCIntString, PlainObj, CCAnyVal}
trait GetSuitePlatform { self: munit.FunSuite =>

test("Get can be auto derived for unary products (AnyVal)") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

Get[CCAnyVal].void
}
Expand All @@ -19,7 +19,7 @@ trait GetSuitePlatform { self: munit.FunSuite =>
}

test("Get should not be derived for non-unary products") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

assertContains(compileErrors("Get[CCIntString]"), "implicit value")
assertContains(compileErrors("Get[(Int, Int)]"), "implicit value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import doobie.testutils.TestClasses.{CCIntString, PlainObj, CCAnyVal}

trait PutSuitePlatform { self: munit.FunSuite =>
test("Put can be auto derived for unary products (AnyVal)") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

Put[CCAnyVal].void
}
Expand All @@ -18,7 +18,7 @@ trait PutSuitePlatform { self: munit.FunSuite =>
}

test("Put should not be derived for non-unary products") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

assertContains(compileErrors("Put[CCIntString]"), "implicit value")
assertContains(compileErrors("Put[(Int, Int)]"), "implicit value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait PutSuitePlatform { self: munit.FunSuite =>
test("Put should be derived for unary products (AnyVal)".ignore) {}

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

assertContains(compileErrors("Put[CCIntString]"), "No given instance")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package doobie.util
import doobie.util.log.{Parameters, Success, ProcessingFailure}

trait QueryLogSuitePlatform { self: QueryLogSuite =>
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

test("[Query] n-arg success") {
val Sql = "select 1 where ? = ?"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ trait ReadSuitePlatform { self: munit.FunSuite =>
case class CaseClassWithFieldWithoutGetInstance(a: String, b: NoGetInstanceForThis)

test("Read should exist for some fancy types") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

Read[Woozle].void
Read[(Woozle, String)].void
Read[(Int, Woozle *: Woozle *: String *: EmptyTuple)].void
}

test("Read should exist for option of some fancy types") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

Read[Option[Woozle]].void
Read[Option[(Woozle, String)]].void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ trait WriteSuitePlatform { self: munit.FunSuite =>
case class CaseClassWithFieldWithoutPutInstance(a: String, b: NoPutInstanceForThis)

test("Write should exist for some fancy types") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

Write[Woozle].void
Write[(Woozle, String)].void
Write[(Int, Woozle *: Woozle *: String *: EmptyTuple)].void
}

test("Write should exist for option of some fancy types") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

Write[Option[Woozle]].void
Write[Option[(Woozle, String)]].void
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/test/scala/doobie/issue/780.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import scala.annotation.nowarn

@nowarn("msg=.*(Foo is never used|(U|u)nused).*")
class `780` extends munit.FunSuite {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

test("deriving instances should work correctly for Write from class scope") {
class Foo[A: Write, B: Write] {
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/test/scala/doobie/util/GetSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GetSuite extends munit.FunSuite with GetSuitePlatform {
}

test("Get should be auto derived for unary products") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

Get[X].void
Get[Q].void
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/test/scala/doobie/util/PutSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PutSuite extends munit.FunSuite with PutSuitePlatform {
}

test("Put should be auto derived for unary products") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

Put[X].void
Put[Q].void
Expand Down
10 changes: 5 additions & 5 deletions modules/core/src/test/scala/doobie/util/ReadSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ReadSuite extends munit.FunSuite with ReadSuitePlatform {
)

test("Read should exist for some fancy types") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

Read[Int].void
Read[(Int, Int)].void
Expand Down Expand Up @@ -55,7 +55,7 @@ class ReadSuite extends munit.FunSuite with ReadSuitePlatform {
}

test("Read is still auto derived for tuples when import is present (no ambiguous implicits)") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}
Read[(Int, Int)].void
Read[(Int, Int, String)].void
Read[(Int, (Int, String))].void
Expand Down Expand Up @@ -111,7 +111,7 @@ class ReadSuite extends munit.FunSuite with ReadSuitePlatform {
}

test("Read should exist for option of some fancy types") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

Read[Option[Int]].void
Read[Option[(Int, Int)]].void
Expand All @@ -123,14 +123,14 @@ class ReadSuite extends munit.FunSuite with ReadSuitePlatform {
}

test("Read should exist for option of Unit") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

Read[Option[Unit]].void
assertEquals(Read[Option[(Int, Unit)]].length, 1).void
}

test("Read should select multi-column instance by default") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

assertEquals(Read[LenStr1].length, 2).void
}
Expand Down
12 changes: 6 additions & 6 deletions modules/core/src/test/scala/doobie/util/WriteSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class WriteSuite extends munit.FunSuite with WriteSuitePlatform {
}

test("Write should exist for some fancy types") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

Write[Int].void
Write[(Int, Int)].void
Expand All @@ -51,7 +51,7 @@ class WriteSuite extends munit.FunSuite with WriteSuitePlatform {
}

test("Write is still auto derived for tuples when import is present (no ambiguous implicits) ") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}
Write[(Int, Int)].void
Write[(Int, Int, String)].void
Write[(Int, (Int, String))].void
Expand Down Expand Up @@ -128,14 +128,14 @@ class WriteSuite extends munit.FunSuite with WriteSuitePlatform {
}

test("Write should exist for Unit") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

Write[Unit].void
assertEquals(Write[(Int, Unit)].length, 1)
}

test("Write should exist for option of some fancy types") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

Write[Option[Int]].void
Write[Option[(Int, Int)]].void
Expand All @@ -145,14 +145,14 @@ class WriteSuite extends munit.FunSuite with WriteSuitePlatform {
}

test("Write should exist for option of Unit") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

Write[Option[Unit]].void
assertEquals(Write[Option[(Int, Unit)]].length, 1)
}

test("Write should select multi-column instance by default") {
import doobie.generic.auto.*
import doobie.generic.auto.{given, *}

assertEquals(Write[LenStr1].length, 2)
}
Expand Down
14 changes: 0 additions & 14 deletions modules/fixme/src/main/scala-2/Fixme.scala

This file was deleted.

24 changes: 24 additions & 0 deletions modules/fixme/src/main/scala/Fixme.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fixme

import doobie.util.*

case class CC(i: Option[Int], s: String, os: Option[String])

case class KK(sc: CC, osc: Option[CC], i: Option[Int], s: String)

object Fixme {
Read.derived[CC]

def lol = {
import doobie.generic.auto.{*, given}

{
MkRead.derived[CC, (Option[Int], String, Option[String])]
Read.fromDerived[CC]
summon[Read[CC]]
Write[CC]
Read[KK]
Write[KK]
}
}
}
Loading

0 comments on commit 3d4d831

Please sign in to comment.