Skip to content

Commit c11a228

Browse files
committed
Add regression test for 16463
Closes #16463
1 parent 912d886 commit c11a228

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

tests/neg/16463.check

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-- Error: tests/neg/16463.scala:42:33 ----------------------------------------------------------------------------------
2+
42 | println(compiletime.constValue[TupleOps.BubbleSort[(1, 2)]]) // error: Recursion limit exceeded
3+
| ^
4+
| Recursion limit exceeded.
5+
| Maybe there is an illegal cyclic reference?
6+
| If that's not the case, you could also try to increase the stacksize using the -Xss JVM option.
7+
| For the unprocessed stack trace, compile with -Yno-decode-stacktraces.
8+
| A recurring operation is (inner to outer):
9+
|
10+
| reduce type EmptyTuple *: EmptyTuple match ...
11+
| reduce type EmptyTuple *: EmptyTuple match ...
12+
| reduce type EmptyTuple *: EmptyTuple match ...
13+
| reduce type EmptyTuple *: EmptyTuple match ...
14+
| reduce type EmptyTuple *: EmptyTuple match ...
15+
| reduce type EmptyTuple *: EmptyTuple match ...
16+
| reduce type EmptyTuple *: EmptyTuple match ...
17+
| reduce type EmptyTuple *: EmptyTuple match ...
18+
| reduce type EmptyTuple *: EmptyTuple match ...
19+
| reduce type EmptyTuple *: EmptyTuple match ...
20+
| ...
21+
|
22+
| reduce type EmptyTuple *: EmptyTuple match ...
23+
| reduce type EmptyTuple *: EmptyTuple match ...
24+
| reduce type EmptyTuple *: EmptyTuple match ...
25+
| reduce type EmptyTuple *: EmptyTuple match ...
26+
| reduce type EmptyTuple *: EmptyTuple match ...
27+
| reduce type EmptyTuple *: EmptyTuple match ...
28+
| reduce type EmptyTuple *: EmptyTuple match ...
29+
| reduce type EmptyTuple *: EmptyTuple match ...
30+
| reduce type ((1 : Int) *: EmptyTuple.type) *: EmptyTuple match ...
31+
| reduce type ((1 : Int), (2 : Int)) match ...

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)