Skip to content

Commit 41eeec4

Browse files
author
Aleksander Boruch-Gruszecki
committed
Test interaction between opaque and match
1 parent e27b6fa commit 41eeec4

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/pos/opaques-patmat.scala

+25
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)