Skip to content

Commit be27e79

Browse files
mbovelEugeneFlesselle
authored andcommitted
Add match-type-printf test
1 parent 2ba368d commit be27e79

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/pos/match-type-printf.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import scala.compiletime.ops.int.+
2+
import scala.compiletime.ops.string.{CharAt, Length, Substring}
3+
import scala.Tuple.*
4+
5+
type ArgTypes[S <: String] <: Tuple = S match
6+
case "" => EmptyTuple
7+
case _ =>
8+
CharAt[S, 0] match
9+
case '%' =>
10+
CharAt[S, 1] match
11+
case 'd' => Int *: ArgTypes[Substring[S, 2, Length[S]]]
12+
case 's' => String *: ArgTypes[Substring[S, 2, Length[S]]]
13+
case _ => ArgTypes[Substring[S, 1, Length[S]]]
14+
15+
def printf(s: String)(t: ArgTypes[s.type]): Unit = ()
16+
17+
def test() =
18+
printf("%s is %d")(("Ada", 36)) // works in Scala 3.2.0, 3.3.0 and 3.4.0
19+
printf("%s is lorem %d")(("Ada", 36)) // works in Scala 3.4.0 but fails in Scala 3.2.0 and 3.3.0

0 commit comments

Comments
 (0)