-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve automatic type id generation, fixes #685
- Loading branch information
Showing
2 changed files
with
37 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
derivation/src/test/scala/io/bullet/borer/derivation/Issue685.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2019-2023 Mathias Doenitz | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package io.bullet.borer.derivation | ||
|
||
// compile-time only | ||
object Issue685: | ||
import io.bullet.borer.* | ||
import io.bullet.borer.derivation.MapBasedCodecs.* | ||
|
||
sealed trait Bar: | ||
def toEither: Either[Int, String] = | ||
this match | ||
case Bar.IntBar(int) => Left(int) | ||
case Bar.StrBar(str) => Right(str) | ||
|
||
object Bar: | ||
case class IntBar(int: Int) extends Bar | ||
case class StrBar(str: String) extends Bar | ||
given Encoder[Bar] = Encoder.ForEither.default[Int, String].contramap[Bar](_.toEither) | ||
|
||
sealed trait Foo | ||
object Foo: | ||
case class Foo1[B <: Bar](b1: B) extends Foo | ||
case class Foo2[B <: Bar](b2: B) extends Foo | ||
|
||
given Encoder[Foo] = { | ||
given Encoder[Foo1[Bar]] = deriveEncoder | ||
given Encoder[Foo2[Bar]] = deriveEncoder | ||
deriveEncoder | ||
} |