Skip to content

Add regression test #11610

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

Merged
merged 1 commit into from
Mar 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/run/i11563.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import scala.compiletime.{constValue, erasedValue, summonInline}
import scala.deriving.Mirror

trait Printer[T]:
def format: String

given Printer[String] with
def format: String = "String"

inline given[T](using mirror: Mirror.ProductOf[T]): Printer[T] = Printer.derived[T]

object Printer:
inline def apply[T](using printer: Printer[T]): Printer[T] = printer

inline def derived[T](using mirror: Mirror.ProductOf[T]): Printer[T] =
val params = summonPrinters[mirror.MirroredElemTypes]
new Printer[T] :
def format: String = params.map(p => p.format).mkString(",")

inline def summonPrinters[Types <: Tuple]: Seq[Printer[?]] = inline erasedValue[Types] match
case _: EmptyTuple => Seq.empty
case _: (v *: vs) => summonInline[Printer[v]] +: summonPrinters[vs]

case class Simple(name: String)

object Test:
def main(args: Array[String]): Unit =
assert(Printer[String].format == "String")
assert(Printer[Simple].format == "String")