From e6ecf82059f5f389cc4cf910d6bc89cc4249b733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Raddum=20Berg?= Date: Tue, 16 Nov 2021 14:32:01 +0100 Subject: [PATCH] Enable support for `derives` in Scala 3 for `Read`, `Write` and `Text` --- modules/core/src/main/scala-3/util/ReadPlatform.scala | 2 +- .../core/src/main/scala-3/util/WritePlatform.scala | 2 +- .../test/scala-3/doobie/util/ReadSuitePlatform.scala | 3 +++ .../test/scala-3/doobie/util/WriteSuitePlatform.scala | 3 +++ .../main/scala-3/doobie/postgres/TextPlatform.scala | 2 +- .../scala-2/doobie/postgres/TextSuitePlatform.scala | 9 +++++++++ .../src/test/scala-3/postgres/TextSuitePlatform.scala | 11 +++++++++++ 7 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 modules/postgres/src/test/scala-2/doobie/postgres/TextSuitePlatform.scala create mode 100644 modules/postgres/src/test/scala-3/postgres/TextSuitePlatform.scala diff --git a/modules/core/src/main/scala-3/util/ReadPlatform.scala b/modules/core/src/main/scala-3/util/ReadPlatform.scala index 741e7ba13..cea807aad 100644 --- a/modules/core/src/main/scala-3/util/ReadPlatform.scala +++ b/modules/core/src/main/scala-3/util/ReadPlatform.scala @@ -20,7 +20,7 @@ trait ReadPlatform: ) // Generic Read for products. - given [P <: Product, A]( + given derived [P <: Product, A]( using m: Mirror.ProductOf[P], i: A =:= m.MirroredElemTypes, w: Read[A] diff --git a/modules/core/src/main/scala-3/util/WritePlatform.scala b/modules/core/src/main/scala-3/util/WritePlatform.scala index ac50865cc..07106f452 100644 --- a/modules/core/src/main/scala-3/util/WritePlatform.scala +++ b/modules/core/src/main/scala-3/util/WritePlatform.scala @@ -22,7 +22,7 @@ trait WritePlatform: ) // Generic write for products. - given [P <: Product, A]( + given derived[P <: Product, A]( using m: Mirror.ProductOf[P], i: m.MirroredElemTypes =:= A, w: Write[A] diff --git a/modules/core/src/test/scala-3/doobie/util/ReadSuitePlatform.scala b/modules/core/src/test/scala-3/doobie/util/ReadSuitePlatform.scala index 9b53b2c01..c2ec716ab 100644 --- a/modules/core/src/test/scala-3/doobie/util/ReadSuitePlatform.scala +++ b/modules/core/src/test/scala-3/doobie/util/ReadSuitePlatform.scala @@ -21,4 +21,7 @@ trait ReadSuitePlatform { self: munit.FunSuite => util.Read[Option[(Int, Woozle *: Woozle *: String *: EmptyTuple)]] } + test("derives") { + case class Foo(a: String, b: Int) derives util.Read + } } diff --git a/modules/core/src/test/scala-3/doobie/util/WriteSuitePlatform.scala b/modules/core/src/test/scala-3/doobie/util/WriteSuitePlatform.scala index 9ece10668..2f8024fee 100644 --- a/modules/core/src/test/scala-3/doobie/util/WriteSuitePlatform.scala +++ b/modules/core/src/test/scala-3/doobie/util/WriteSuitePlatform.scala @@ -21,4 +21,7 @@ trait WriteSuitePlatform { self: munit.FunSuite => util.Write[Option[(Int, Woozle *: Woozle *: String *: EmptyTuple)]] } + test("derives") { + case class Foo(a: String, b: Int) derives util.Write + } } diff --git a/modules/postgres/src/main/scala-3/doobie/postgres/TextPlatform.scala b/modules/postgres/src/main/scala-3/doobie/postgres/TextPlatform.scala index 43c30b907..a8394ff80 100644 --- a/modules/postgres/src/main/scala-3/doobie/postgres/TextPlatform.scala +++ b/modules/postgres/src/main/scala-3/doobie/postgres/TextPlatform.scala @@ -17,7 +17,7 @@ trait TextPlatform { this: Text.type => (h product t).contramap(l => (l.head, l.tail)) // Put is available for single-element products. - given [P <: Product, A]( + given derived[P <: Product, A]( using m: Mirror.ProductOf[P], i: m.MirroredElemTypes =:= A, t: Text[A] diff --git a/modules/postgres/src/test/scala-2/doobie/postgres/TextSuitePlatform.scala b/modules/postgres/src/test/scala-2/doobie/postgres/TextSuitePlatform.scala new file mode 100644 index 000000000..b2b31c521 --- /dev/null +++ b/modules/postgres/src/test/scala-2/doobie/postgres/TextSuitePlatform.scala @@ -0,0 +1,9 @@ +// Copyright (c) 2013-2020 Rob Norris and Contributors +// This software is licensed under the MIT License (MIT). +// For more information see LICENSE or https://opensource.org/licenses/MIT + +package doobie.postgres + +trait TextSuitePlatform { self: munit.FunSuite => + +} diff --git a/modules/postgres/src/test/scala-3/postgres/TextSuitePlatform.scala b/modules/postgres/src/test/scala-3/postgres/TextSuitePlatform.scala new file mode 100644 index 000000000..8baf73259 --- /dev/null +++ b/modules/postgres/src/test/scala-3/postgres/TextSuitePlatform.scala @@ -0,0 +1,11 @@ +// Copyright (c) 2013-2020 Rob Norris and Contributors +// This software is licensed under the MIT License (MIT). +// For more information see LICENSE or https://opensource.org/licenses/MIT + +package doobie.postgres + +trait TextSuitePlatform { self: munit.FunSuite => + test("derives") { + case class Foo(a: String, b: Int) derives Text + } +}