Skip to content

Commit

Permalink
Use simple typeable for simple case classes (#232)
Browse files Browse the repository at this point in the history
* add failing test for scala.Enumeration

* use simple typeable for simple case classes
  • Loading branch information
dwickern authored Jun 12, 2024
1 parent 7ce945c commit 6655cc5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,10 @@ object TypeableMacros:
val owner = normalizeModuleClass(sym.owner)

qual match
case Some(_) if sym.flags.is(Flags.Case) => mkCaseClassTypeable
case None => mkNamedSimpleTypeable
case Some(tp: TypeRef) if normalizeModuleClass(tp.typeSymbol) == owner => mkNamedSimpleTypeable
case Some(tp: TermRef) if normalizeModuleClass(tp.termSymbol) == owner => mkNamedSimpleTypeable
case Some(_) if sym.flags.is(Flags.Case) => mkCaseClassTypeable
case Some(_) if sym.flags.is(Flags.Sealed) => mkSumTypeable
case _ => report.errorAndAbort(s"No Typeable for type ${target.show} with a dependent prefix")

Expand Down
13 changes: 13 additions & 0 deletions modules/typeable/src/test/scala/shapeless3/typeable/typeable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -609,5 +609,18 @@ class TypeableTests:
assertEquals(ti.describe, "Tree[Int]")
assertEquals(ti.toString, "Typeable[Tree[Int]]")

@Test
def testEnumeration(): Unit =
val tc = Typeable[CaseClassWithEnumeration]
val cc = CaseClassWithEnumeration()
assert(tc.castable(cc))
assert(tc.cast(cc).contains(cc))

object TypeableTests:
final case class Tree[+A](value: A, children: Vector[Tree[A]])

object E extends scala.Enumeration:
val A = Value("a")
val B = Value("b")

case class CaseClassWithEnumeration(name: String = "", e: E.Value = E.A)

0 comments on commit 6655cc5

Please sign in to comment.