Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
liufengyun committed Jan 21, 2021
1 parent 65ef982 commit 53db02e
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions tests/patmat/i10961.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
object test0 {
object :+ {
def unapply[T](l: ::[T]): (List[T], T) = (l.tail, l.head)
}

def f(xs: List[Int]) =
xs match
case init :+ last => ()
case Nil => ()
}

object test1 {
import scala.annotation.covers

type /[T, U] = T @covers[U]

object :+ {
def unapply[T](l: List[T]): Option[(List[T], T)] / ::[T] = ???
}

def f(xs: List[Int]) =
xs match
case init :+ last => ()
case Nil => ()
}

object test2lib {
import scala.annotation.covers

class ValDef
class TypeDef
opaque type ValDefs <: List[ValDef] = List[ValDef]
opaque type TypeDefs <: List[TypeDef] = List[TypeDef]

type ParamClause = ValDefs | TypeDefs

object ValDefs with
def unapply(pc: ParamClause): Option[ValDefs] @covers[ValDefs] = ??? // matches empty list and all lists of ValDefs

def apply(vals: List[ValDef]): ValDefs = vals

object TypeDefs with
def unapply(pc: ParamClause): Option[TypeDefs] @covers[TypeDefs] = ??? // matches non-empty lists of TypeDefs

def apply(tdefs: List[TypeDef]): TypeDefs =
assert(tdefs.nonEmpty)
tdefs
}

object test2 {
import test2lib._

def f(pc: ParamClause) =
pc match
case ValDefs(vs) => ()
case TypeDefs(ts) => ()
}

object test3lib {
import scala.annotation.covers

opaque type Nat <: Int = Int
opaque type Neg <: Int = Int

type Num = Nat | Neg

object Nat with
def unapply(x: Num): Option[Nat] @covers[Nat] =
if x >= 0 then Some(x) else None

def apply(x: Int): Nat =
assert(x >= 0)
x

object Neg with
def unapply(x: Num): Option[Neg] @covers[Neg] =
if x < 0 then Some(x) else None

def apply(x: Int): Nat =
assert(x < 0)
x
}

object test3 {
import test3lib._

def foo(x: Num) =
x match
case Nat(x) =>
case Neg(x) =>
}

0 comments on commit 53db02e

Please sign in to comment.