Skip to content

Commit e7d07d2

Browse files
committed
Add regression test
Closes scala#11563 Possibly fixed by scala#11557
1 parent 5fa55b1 commit e7d07d2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/run/i11563.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import scala.compiletime.{constValue, erasedValue, summonInline}
2+
import scala.deriving.Mirror
3+
4+
trait Printer[T]:
5+
def format: String
6+
7+
given Printer[String] with
8+
def format: String = "String"
9+
10+
inline given[T](using mirror: Mirror.ProductOf[T]): Printer[T] = Printer.derived[T]
11+
12+
object Printer:
13+
inline def apply[T](using printer: Printer[T]): Printer[T] = printer
14+
15+
inline def derived[T](using mirror: Mirror.ProductOf[T]): Printer[T] =
16+
val params = summonPrinters[mirror.MirroredElemTypes]
17+
new Printer[T] :
18+
def format: String = params.map(p => p.format).mkString(",")
19+
20+
inline def summonPrinters[Types <: Tuple]: Seq[Printer[?]] = inline erasedValue[Types] match
21+
case _: EmptyTuple => Seq.empty
22+
case _: (v *: vs) => summonInline[Printer[v]] +: summonPrinters[vs]
23+
24+
case class Simple(name: String)
25+
26+
object Test:
27+
def main(args: Array[String]): Unit =
28+
assert(Printer[String].format == "String")
29+
assert(Printer[Simple].format == "String")

0 commit comments

Comments
 (0)