softwaremill / magnolia

Easy, fast, transparent generic derivation of typeclass instances
https://softwaremill.com/open-source/
Apache License 2.0
754 stars 116 forks source link

Dealias types when deriving names (Scala 3) #468

Closed kciesielski closed 1 year ago

kciesielski commented 1 year ago

Fixes #467 for Scala 3

This PR ensures that type names are derived from dealiased underlying types. Inspired by an issue reported in tapir:

//> using scala 3.3.0-RC6
//> using dep com.softwaremill.sttp.tapir::tapir-core:1.4.0
import sttp.tapir.*
import sttp.tapir.generic.auto.*

case class Foo[T](t: T)

object Domain1:
  type Type = Int

object Domain2:
  type Type = String

@main
def main =
  val d1Schema = summon[Schema[Foo[Domain1.Type]]]
  val d2Schema = summon[Schema[Foo[Domain2.Type]]]
  println(d1Schema.name.map(_.show)) // Some(.Foo[Type]), should be Some(.Foo[Int])
  println(d2Schema.name.map(_.show)) // Some(.Foo[Type]), should be Some(.Foo[String])

This issue doesn't happen for Scala 2, where dealiasing seems to be correctly applied.