From c11a2289408928b0fab3d0b27e3001cfb56752de Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Fri, 26 Apr 2024 11:03:17 +0200 Subject: [PATCH] Add regression test for 16463 Closes #16463 --- tests/neg/16463.check | 31 +++++++++++++++++++++++++++++++ tests/neg/16463.scala | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 tests/neg/16463.check create mode 100644 tests/neg/16463.scala diff --git a/tests/neg/16463.check b/tests/neg/16463.check new file mode 100644 index 000000000000..421f0f4c2d82 --- /dev/null +++ b/tests/neg/16463.check @@ -0,0 +1,31 @@ +-- Error: tests/neg/16463.scala:42:33 ---------------------------------------------------------------------------------- +42 | println(compiletime.constValue[TupleOps.BubbleSort[(1, 2)]]) // error: Recursion limit exceeded + | ^ + | Recursion limit exceeded. + | Maybe there is an illegal cyclic reference? + | If that's not the case, you could also try to increase the stacksize using the -Xss JVM option. + | For the unprocessed stack trace, compile with -Yno-decode-stacktraces. + | A recurring operation is (inner to outer): + | + | reduce type EmptyTuple *: EmptyTuple match ... + | reduce type EmptyTuple *: EmptyTuple match ... + | reduce type EmptyTuple *: EmptyTuple match ... + | reduce type EmptyTuple *: EmptyTuple match ... + | reduce type EmptyTuple *: EmptyTuple match ... + | reduce type EmptyTuple *: EmptyTuple match ... + | reduce type EmptyTuple *: EmptyTuple match ... + | reduce type EmptyTuple *: EmptyTuple match ... + | reduce type EmptyTuple *: EmptyTuple match ... + | reduce type EmptyTuple *: EmptyTuple match ... + | ... + | + | reduce type EmptyTuple *: EmptyTuple match ... + | reduce type EmptyTuple *: EmptyTuple match ... + | reduce type EmptyTuple *: EmptyTuple match ... + | reduce type EmptyTuple *: EmptyTuple match ... + | reduce type EmptyTuple *: EmptyTuple match ... + | reduce type EmptyTuple *: EmptyTuple match ... + | reduce type EmptyTuple *: EmptyTuple match ... + | reduce type EmptyTuple *: EmptyTuple match ... + | reduce type ((1 : Int) *: EmptyTuple.type) *: EmptyTuple match ... + | reduce type ((1 : Int), (2 : Int)) match ... diff --git a/tests/neg/16463.scala b/tests/neg/16463.scala new file mode 100644 index 000000000000..80a84cf02bc8 --- /dev/null +++ b/tests/neg/16463.scala @@ -0,0 +1,43 @@ +//> using scala "3.2.1" + +import scala.compiletime.ops.int._ + +object TupleOps { + import Tuple._ + + type Reduce[T <: NonEmptyTuple, F[_, _]] = + Fold[Tuple.Tail[T], Tuple.Head[T], F] + + type Maximum[T <: NonEmptyTuple] = Reduce[ + T, + [A, B] =>> (A, B) match { + case (Int, Int) => A `Max` B + } + ] + + type IndexOfRec[T <: Tuple, Elem, I <: Int] = Tuple.Elem[T, I] match { + case Elem => I + case _ => IndexOfRec[T, Elem, I + 1] + } + + type IndexOf[T <: Tuple, Elem] = IndexOfRec[T, Elem, 0] + + type DropLargest[T <: NonEmptyTuple] = + T `IndexOf` Maximum[T] match { + case Int => + ( + (T `Take` (T `IndexOf` Maximum[T])) `Concat` + (T `Drop` ((T `IndexOf` Maximum[T]) + 1)) + ) *: EmptyTuple + } + + type BubbleSort[T <: Tuple] = T match { + case EmptyTuple => EmptyTuple + case NonEmptyTuple => + BubbleSort[DropLargest[T]] `Concat` (Maximum[T] *: EmptyTuple) + } +} + +object demo extends App { + println(compiletime.constValue[TupleOps.BubbleSort[(1, 2)]]) // error: Recursion limit exceeded +}