forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend pattern type constraining to closed hierarchies
- Loading branch information
Showing
5 changed files
with
49 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Test: | ||
def foo(as: Seq[Int]) = | ||
val List(_, bs: _*) = as: @unchecked | ||
val cs: Seq[Int] = bs | ||
|
||
class Test2: | ||
def foo(as: SSeq[Int]) = | ||
val LList(_, tail) = as: @unchecked | ||
val cs: SSeq[Int] = tail | ||
|
||
trait SSeq[+A] | ||
sealed trait LList[+A] extends SSeq[A] | ||
final case class CCons[+A](head: A, tail: LList[A]) extends LList[A] | ||
case object NNil extends LList[Nothing] | ||
object LList: | ||
def unapply[A](xs: LList[A]): Extractor[A] = Extractor[A](xs) | ||
final class Extractor[A](private val xs: LList[A]) extends AnyVal: | ||
def get: this.type = this | ||
def isEmpty: Boolean = xs.isInstanceOf[CCons[?]] | ||
def _1: A = xs.asInstanceOf[CCons[A]].head | ||
def _2: SSeq[A] = xs.asInstanceOf[CCons[A]].tail |