Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
pablf committed Jun 30, 2024
1 parent 6c531a8 commit a709895
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ private case class DeriveSchema()(using val ctx: Quotes) {
val children = TypeRepr.of[T].typeSymbol.children
val childrenFields = children.map(_.declaredFields.length)
val childrenFieldsConstructor = children.map(_.caseFields.length)
val isSimpleEnum: Boolean = childrenFieldsConstructor.forall( _ == 0) && childrenFields.forall( _ <= numParentFields) && types.flatMap(_.children).isEmpty
val isSimpleEnum: Boolean = childrenFieldsConstructor.forall( _ == 0) && childrenFields.forall( _ <= numParentFields) && types.flatmap(_.typeSymbol.children).isEmpty
val hasSimpleEnumAnn: Boolean = TypeRepr.of[T].typeSymbol.hasAnnotation(TypeRepr.of[_root_.zio.schema.annotation.simpleEnum].typeSymbol)

val docAnnotationExpr = TypeRepr.of[T].typeSymbol.docstring.map { docstring =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ trait VersionSpecificDeriveSchemaSpec extends ZIOSpecDefault {
case A extends NonSimpleEnum5(0, "")
case B(n: Int) extends NonSimpleEnum5(n, "")

sealed trait NonSimpleTrait
sealed trait NonSimpleMiddle extends NonSimpleTrait
case class NonSimpleLeaf() extends NonSimpleMiddle

def versionSpecificSuite = Spec.labeled(
"Scala 3 specific tests",
suite("Derivation")(
Expand Down Expand Up @@ -97,6 +101,10 @@ trait VersionSpecificDeriveSchemaSpec extends ZIOSpecDefault {
assertTrue(derived4.annotations.isEmpty) &&
assertTrue(derived5.annotations.isEmpty)
},
test("doesn't assigns simpleEnum to enum with intermediate trait") {
val derived = DeriveSchema.gen[NonSimpleTrait]
assertTrue(derived.annotations.isEmpty)
}
test("derive different annotations for parent and child in enum") {
val parent = DeriveSchema.gen[ColourAnnotations]
val child = parent match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,6 @@ object DeriveSchemaSpec extends ZIOSpecDefault with VersionSpecificDeriveSchemaS
sealed trait SimpleEnum2
case class SimpleClass2() extends SimpleEnum2

sealed trait NonSimpleTrait
sealed trait NonSimpleMiddle extends NonSimpleTrait
case class NonSimpleLeaf() extends NonSimpleMiddle

sealed abstract class AbstractBaseClass(val x: Int)
final case class ConcreteClass1(override val x: Int, y: Int) extends AbstractBaseClass(x)
final case class ConcreteClass2(override val x: Int, s: String) extends AbstractBaseClass(x)
Expand Down Expand Up @@ -497,10 +493,6 @@ object DeriveSchemaSpec extends ZIOSpecDefault with VersionSpecificDeriveSchemaS
val derived = DeriveSchema.gen[SimpleEnum2]
assertTrue(derived.annotations == Chunk(simpleEnum(true)))
},
test("doesn't derives simpleEnum when extending subclasses") {
val derived = DeriveSchema.gen[NonSimpleTrait]
assertTrue(derived.annotations.isEmpty)
},
test("correctly derives schema for abstract sealed class with case class subclasses") {
val derived = DeriveSchema.gen[AbstractBaseClass]
val expected: Schema[AbstractBaseClass] =
Expand Down

0 comments on commit a709895

Please sign in to comment.