forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add note and a test to show the prefix rule for path subsuming
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import language.experimental.modularity | ||
import language.experimental.captureChecking | ||
import caps.Capability | ||
|
||
class F: | ||
val f: AnyRef^ = ??? | ||
|
||
case class B(tracked val a: A) extends F, Capability | ||
|
||
class A extends F, Capability: | ||
val b: B { val a: A.this.type } = B(this) | ||
|
||
def test(a: A) = | ||
val x: a.b.type = a.b | ||
val y: x.a.type = x.a | ||
// x and y are two distinct singleton types with following properties: | ||
// x =:= a.b | ||
// y =:= x.a =:= a.b.a =:= a | ||
|
||
val cx: AnyRef^{x} = ??? | ||
val cy: AnyRef^{y} = ??? | ||
val caf: AnyRef^{a.f} = ??? | ||
val cabf: AnyRef^{a.b.f} = ??? | ||
val cxf: AnyRef^{x.f} = ??? | ||
val cyf: AnyRef^{y.f} = ??? | ||
|
||
// x and y subsume to each other: | ||
// * {x} <:< {y}: the underlying singleton of y is x.a, | ||
// and the underlying singleton of x.a is a, | ||
// which is a prefix for the underlying type of x (a.b), | ||
// hence {x} <:< {y}; | ||
// * {y} <:< {x}: by underlying singleton of y is x.a, whose prefix is x. | ||
// Hence, {x} =:= {y}. | ||
val x2y: AnyRef^{y} = cx | ||
val y2x: AnyRef^{x} = cy | ||
|
||
val yf2af: AnyRef^{a.f} = cyf | ||
val af2yf: AnyRef^{y.f} = caf | ||
val xf2abf: AnyRef^{a.b.f} = cxf | ||
val abf2xf: AnyRef^{x.f} = cabf | ||
|
||
// Since `x !=:= y`, {x.f} !=:= {y.f} | ||
val yf2xf: AnyRef^{x.f} = cyf // error | ||
val xf2yf: AnyRef^{y.f} = cxf // error |