From 3c1c0477af2b1123c409aa1bf4ff1fff22f6aea7 Mon Sep 17 00:00:00 2001 From: aherlihy Date: Mon, 11 Aug 2025 15:13:51 +0200 Subject: [PATCH] Additional test for named tuple custom extractor with mismatched type [Cherry-picked f1f80c1671c0dfbbe8fe7ce84f5e139fa9bb1778] --- tests/neg/i23552.scala | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/neg/i23552.scala diff --git a/tests/neg/i23552.scala b/tests/neg/i23552.scala new file mode 100644 index 000000000000..ea3d0ff7f874 --- /dev/null +++ b/tests/neg/i23552.scala @@ -0,0 +1,32 @@ +import NamedTuple.AnyNamedTuple + +sealed trait Z +sealed trait S[n] + +type TupleList[+A, N] <: AnyNamedTuple = + N match + case Z => NamedTuple.Empty + case S[n] => (head: A, tail: TupleList[A, n]) + +sealed trait Vect[+A, N]: + def ::[A1 >: A](a: A1): Vect[A1, S[N]] = + Vect.Cons(a, this) + + def toTupleList: TupleList[A, N] + +object Vect: + case object Empty extends Vect[Nothing, Z]: + override def toTupleList: TupleList[Nothing, Z] = NamedTuple.Empty + + case class Cons[A, N](head: A, tail: Vect[A, N]) extends Vect[A, S[N]]: + override def toTupleList: TupleList[A, S[N]] = (head, tail.toTupleList) + +object Foo: + def unapply[A, N](as: Vect[A, N]): Some[TupleList[A, N]] = + Some(as.toTupleList) + +@main +def test: Unit = + (1 :: 2 :: 3 :: Vect.Empty) match + // missing parens around named tuple inside Foo causes compiler crash + case Foo(head = h, tail = t) => ??? // error \ No newline at end of file