File tree 2 files changed +44
-0
lines changed
2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ refinedScrutinee
2
+ ok
3
+ 9
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments