Skip to content

Commit 8825b07

Browse files
authored
Add regression test for #16463 (#20269)
Closes #16463
1 parent 5e533a8 commit 8825b07

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/neg/16463.scala

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//> using scala "3.2.1"
2+
3+
import scala.compiletime.ops.int._
4+
5+
object TupleOps {
6+
import Tuple._
7+
8+
type Reduce[T <: NonEmptyTuple, F[_, _]] =
9+
Fold[Tuple.Tail[T], Tuple.Head[T], F]
10+
11+
type Maximum[T <: NonEmptyTuple] = Reduce[
12+
T,
13+
[A, B] =>> (A, B) match {
14+
case (Int, Int) => A `Max` B
15+
}
16+
]
17+
18+
type IndexOfRec[T <: Tuple, Elem, I <: Int] = Tuple.Elem[T, I] match {
19+
case Elem => I
20+
case _ => IndexOfRec[T, Elem, I + 1]
21+
}
22+
23+
type IndexOf[T <: Tuple, Elem] = IndexOfRec[T, Elem, 0]
24+
25+
type DropLargest[T <: NonEmptyTuple] =
26+
T `IndexOf` Maximum[T] match {
27+
case Int =>
28+
(
29+
(T `Take` (T `IndexOf` Maximum[T])) `Concat`
30+
(T `Drop` ((T `IndexOf` Maximum[T]) + 1))
31+
) *: EmptyTuple
32+
}
33+
34+
type BubbleSort[T <: Tuple] = T match {
35+
case EmptyTuple => EmptyTuple
36+
case NonEmptyTuple =>
37+
BubbleSort[DropLargest[T]] `Concat` (Maximum[T] *: EmptyTuple)
38+
}
39+
}
40+
41+
object demo extends App {
42+
println(compiletime.constValue[TupleOps.BubbleSort[(1, 2)]]) // error: Recursion limit exceeded
43+
}

0 commit comments

Comments
 (0)