Skip to content

Commit dfb8174

Browse files
committed
WIP call refinedScrutinee
1 parent 850ceb4 commit dfb8174

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

tests/run/refined-binding-3.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
refinedScrutinee
2+
ok
3+
9

tests/run/refined-binding-3.scala

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
sealed trait Foo {
3+
4+
type X
5+
type Y <: X
6+
7+
def x: X
8+
9+
def f(y: Y) = println("ok")
10+
11+
object Z {
12+
def unapply(arg: X) = new Opt {
13+
type Scrutinee = arg.type
14+
def refinedScrutinee: Y & Scrutinee = {
15+
println("refinedScrutinee")
16+
arg.asInstanceOf[Y & Scrutinee]
17+
}
18+
}
19+
}
20+
21+
abstract class Opt {
22+
type Scrutinee <: Singleton
23+
def refinedScrutinee: Y & Scrutinee
24+
def get: Int = 9
25+
def isEmpty: Boolean = false
26+
}
27+
}
28+
29+
object Test {
30+
def main(args: Array[String]): Unit = {
31+
test(new Foo { type X = Int; type Y = Int; def x: X = 1 })
32+
}
33+
34+
def test(foo: Foo): Unit = {
35+
foo.x match {
36+
case x @ foo.Z(i) => // `x` is refined to type `Y`
37+
foo.f(x)
38+
println(i)
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)