-
-
Notifications
You must be signed in to change notification settings - Fork 25
Accommodate user-defined mirrors #219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,16 +16,16 @@ | |
|
|
||
| package shapeless3.deriving | ||
|
|
||
| import cats.Eval | ||
| import org.junit.Assert.* | ||
| import org.junit.Test | ||
| import shapeless3.deriving.adts.* | ||
| import shapeless3.deriving.adts.OptE.{NnE, SmE} | ||
|
|
||
| import scala.annotation.tailrec | ||
| import scala.compiletime.constValueTuple | ||
|
|
||
| import cats.Eval | ||
|
|
||
| import adts.* | ||
| import OptE.{SmE, NnE} | ||
| import scala.compiletime.{constValueTuple, testing} | ||
| import scala.compiletime.testing.typeCheckErrors | ||
| import scala.deriving.Mirror | ||
|
|
||
| // Tests | ||
|
|
||
|
|
@@ -393,3 +393,52 @@ class DerivationTests: | |
| assertEquals(Right(ISB(42, "foo", true)), parser.parseShort("s=foo,i=42,b=true,hidden=?")) | ||
| assertEquals(Left("Missing field 's';"), parser.parseShort("i=42,b=kinda")) | ||
| assertEquals(Left("Invalid field 'broken';"), parser.parseShort("i=42,broken,?")) | ||
|
|
||
| @Test | ||
| def userDefinedMirrors(): Unit = | ||
| def assertImportSuggested(errors: List[testing.Error]): Unit = | ||
| assertEquals(1, errors.size) | ||
| val message = errors.head.message.trim | ||
| assert(message.startsWith("No given instance of type")) | ||
| assert(message.endsWith("Generic.fromMirror")) | ||
|
Comment on lines
+399
to
+403
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tschuchortdev the default message already suggests the import so I think it's adequate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright. In my experience those suggestions are rarely productive, so I tend to ignore them. |
||
|
|
||
| def show[A](using | ||
| m: Mirror.ProductOf[A] { | ||
| type MirroredLabel = "ISB" | ||
| type MirroredElemLabels = ("i", "s", "b") | ||
| type MirroredElemTypes = (Int, String, Boolean) | ||
| } | ||
| ): Unit = | ||
| assertImportSuggested(typeCheckErrors("K0.Generic[A]")) | ||
| import K0.Generic.fromMirror | ||
| assertEquals(m, K0.Generic[A]) | ||
| assertNotNull(Show[A]) | ||
|
|
||
| def bifunctor[F[_, _]](using | ||
| m: Mirror.Sum { | ||
| type MirroredType[A, B] = F[A, B] | ||
| type MirroredMonoType = F[Any, Any] | ||
| type MirroredElemTypes[A, B] = ((A, B), Unit) | ||
| } | ||
| ): Unit = | ||
| assertImportSuggested(typeCheckErrors("K2.Generic[F]")) | ||
| import K2.Generic.fromMirror | ||
| assertEquals(m, K2.CoproductGeneric[F]) | ||
| assertNotNull(Bifunctor[F]) | ||
|
|
||
| def functorK[Alg[_[_]]](using | ||
| m: Mirror.Product { | ||
| type MirroredType[F[_]] = Alg[F] | ||
| type MirroredMonoType = Alg[[_] =>> Any] | ||
| type MirroredElemTypes[F[_]] = (F[String], F[Int]) | ||
| } | ||
| ): Unit = | ||
| assertImportSuggested(typeCheckErrors("K11.Generic[Alg]")) | ||
| import K11.Generic.fromMirror | ||
| assertEquals(m, K11.Generic[Alg]) | ||
| assertNotNull(FunctorK[Alg]) | ||
|
|
||
| show[ISB] | ||
| bifunctor[ListF] | ||
| functorK[Order] | ||
| end userDefinedMirrors | ||
Uh oh!
There was an error while loading. Please reload this page.