|
| 1 | +import language.experimental.modularity |
| 2 | +import language.experimental.captureChecking |
| 3 | +import caps.Capability |
| 4 | + |
| 5 | +class F: |
| 6 | + val f: AnyRef^ = ??? |
| 7 | + |
| 8 | +case class B(tracked val a: A) extends F, Capability |
| 9 | + |
| 10 | +class A extends F, Capability: |
| 11 | + val b: B { val a: A.this.type } = B(this) |
| 12 | + |
| 13 | +def test(a: A) = |
| 14 | + val x: a.b.type = a.b |
| 15 | + val y: x.a.type = x.a |
| 16 | + // x and y are two distinct singleton types with following properties: |
| 17 | + // x =:= a.b |
| 18 | + // y =:= x.a =:= a.b.a =:= a |
| 19 | + |
| 20 | + val cx: AnyRef^{x} = ??? |
| 21 | + val cy: AnyRef^{y} = ??? |
| 22 | + val caf: AnyRef^{a.f} = ??? |
| 23 | + val cabf: AnyRef^{a.b.f} = ??? |
| 24 | + val cxf: AnyRef^{x.f} = ??? |
| 25 | + val cyf: AnyRef^{y.f} = ??? |
| 26 | + |
| 27 | + // x and y subsume to each other: |
| 28 | + // * {x} <:< {y}: the underlying singleton of y is x.a, |
| 29 | + // and the underlying singleton of x.a is a, |
| 30 | + // which is a prefix for the underlying type of x (a.b), |
| 31 | + // hence {x} <:< {y}; |
| 32 | + // * {y} <:< {x}: by underlying singleton of y is x.a, whose prefix is x. |
| 33 | + // Hence, {x} =:= {y}. |
| 34 | + val x2y: AnyRef^{y} = cx |
| 35 | + val y2x: AnyRef^{x} = cy |
| 36 | + |
| 37 | + val yf2af: AnyRef^{a.f} = cyf |
| 38 | + val af2yf: AnyRef^{y.f} = caf |
| 39 | + val xf2abf: AnyRef^{a.b.f} = cxf |
| 40 | + val abf2xf: AnyRef^{x.f} = cabf |
| 41 | + |
| 42 | + // Since `x !=:= y`, {x.f} !=:= {y.f} |
| 43 | + val yf2xf: AnyRef^{x.f} = cyf // error |
| 44 | + val xf2yf: AnyRef^{y.f} = cxf // error |
0 commit comments