Skip to content

Commit f1f80c1

Browse files
committed
Additional test for named tuple custom extractor with mismatched type
1 parent b13d617 commit f1f80c1

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/neg/i23552.scala

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import NamedTuple.AnyNamedTuple
2+
3+
sealed trait Z
4+
sealed trait S[n]
5+
6+
type TupleList[+A, N] <: AnyNamedTuple =
7+
N match
8+
case Z => NamedTuple.Empty
9+
case S[n] => (head: A, tail: TupleList[A, n])
10+
11+
sealed trait Vect[+A, N]:
12+
def ::[A1 >: A](a: A1): Vect[A1, S[N]] =
13+
Vect.Cons(a, this)
14+
15+
def toTupleList: TupleList[A, N]
16+
17+
object Vect:
18+
case object Empty extends Vect[Nothing, Z]:
19+
override def toTupleList: TupleList[Nothing, Z] = NamedTuple.Empty
20+
21+
case class Cons[A, N](head: A, tail: Vect[A, N]) extends Vect[A, S[N]]:
22+
override def toTupleList: TupleList[A, S[N]] = (head, tail.toTupleList)
23+
24+
object Foo:
25+
def unapply[A, N](as: Vect[A, N]): Some[TupleList[A, N]] =
26+
Some(as.toTupleList)
27+
28+
@main
29+
def test: Unit =
30+
(1 :: 2 :: 3 :: Vect.Empty) match
31+
// missing parens around named tuple inside Foo causes compiler crash
32+
case Foo(head = h, tail = t) => ??? // error

0 commit comments

Comments
 (0)