From 1036c83cb5c3f34764edaa4fbc776a68361445b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Wed, 30 Aug 2023 17:35:28 +0200 Subject: [PATCH] Fix #18211: Add regression test. This is also fixed by the parent commit. --- tests/pos/i18211.scala | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/pos/i18211.scala diff --git a/tests/pos/i18211.scala b/tests/pos/i18211.scala new file mode 100644 index 000000000000..b268b23f2b1a --- /dev/null +++ b/tests/pos/i18211.scala @@ -0,0 +1,39 @@ +import scala.compiletime.ops.int.* + +type AnyInt[A <: Int] <: Int = A match { + case _ => A +} + +type IndexOf[A, T <: Tuple] <: Int = T match { + case EmptyTuple => -1 + case A *: t => 0 + case _ *: t => + IndexOf[A, t] match { + case -1 => -1 + case AnyInt[a] => S[a] + } +} + +type Indexes[A, T <: Tuple] +object Indexes { + given of[A, T <: Tuple](using IndexOf[A, T] >= 0 =:= true)(using + index: ValueOf[IndexOf[A, T]], + next: Indexes[A, Tuple.Drop[T, S[IndexOf[A, T]]]] + ): Indexes[A, T] = ??? + + given empty[A, T <: Tuple](using IndexOf[A, T] =:= -1): Indexes[A, T] = ??? +} + +class GetAll[A]: + def apply[T <: Tuple](t: T)(using indexes: Indexes[A, T]): List[A] = ??? + +def getAll[A]: GetAll[A] = new GetAll[A] + +def test = + // the code here is trying to get all values from a tuple that has type [X] as a list + + // this works if there are only two strings in the tuple + getAll[String](("str1", 1, "str2", false)) + + //but this not compiles if there are more than two strings in the tuple + getAll[String](("str1", 1, "str2", false, "str3"))