Skip to content

Additional test for named tuple custom extractor with mismatched type #23706

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions tests/neg/i23552.scala
Original file line number Diff line number Diff line change
@@ -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
Loading