-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65ef982
commit 53db02e
Showing
1 changed file
with
91 additions
and
0 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
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) => | ||
} |