Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regression test for 16463 #20269

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions tests/neg/16463.scala
Original file line number Diff line number Diff line change
@@ -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
mbovel marked this conversation as resolved.
Show resolved Hide resolved
}
Loading