We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 81b3038 + 41eeec4 commit 7a86d5bCopy full SHA for 7a86d5b
tests/pos/opaques-patmat.scala
@@ -0,0 +1,25 @@
1
+object OpaquePatmat {
2
+ opaque type Pos = Int
3
+ object Pos {
4
+ def mkPos(i: Int): Pos = {
5
+ require(i > 0)
6
+ i
7
+ }
8
+ def coerce[F[_]](fa: F[Int]): F[Pos] = fa
9
10
+
11
+ sealed trait Expr[T]
12
+ final case class PosExpr(p: Pos) extends Expr[Pos]
13
+ final case class IntExpr(i: Int) extends Expr[Int]
14
+ final case class StrExpr(s: String) extends Expr[String]
15
16
+ def eval(e: Expr[Pos]): Pos = e match {
17
+ case PosExpr(p) => p
18
+ // both of the patterns need to be well-typed here,
19
+ // since Pos is potentially equal to any other type
20
+ case IntExpr(_) => Pos.mkPos(1)
21
+ case StrExpr(_) => ???
22
23
24
+ eval(Pos.coerce[Expr](IntExpr(-1)))
25
+}
0 commit comments