|
| 1 | +trait Cap |
| 2 | + |
| 3 | +def main(io: {*} Cap, fs: {*} Cap): Unit = { |
| 4 | + val test1: {} Unit -> Unit = _ => { // error |
| 5 | + type Op = [T] -> ({io} T -> Unit) -> Unit |
| 6 | + val f: ({io} Cap) -> Unit = ??? |
| 7 | + val op: Op = ??? |
| 8 | + op[{io} Cap](f) |
| 9 | + // expected type of f: {io} (box {io} Cap) -> Unit |
| 10 | + // actual type: ({io} Cap) -> Unit |
| 11 | + // adapting f to the expected type will also |
| 12 | + // charge the environment with {io} |
| 13 | + } |
| 14 | + |
| 15 | + val test2: {} Unit -> Unit = _ => { |
| 16 | + type Box[X] = X |
| 17 | + type Op0[X] = Box[X] -> Unit |
| 18 | + type Op1[X] = Unit -> Box[X] |
| 19 | + val f: Unit -> ({io} Cap) -> Unit = ??? |
| 20 | + val test: {} Op1[{io} Op0[{io} Cap]] = f |
| 21 | + // expected: {} Unit -> box {io} (box {io} Cap) -> Unit |
| 22 | + // actual: Unit -> ({io} Cap) -> Unit |
| 23 | + // |
| 24 | + // although adapting `({io} Cap) -> Unit` to |
| 25 | + // `box {io} (box {io} Cap) -> Unit` will leak the |
| 26 | + // captured variables {io}, but since it is inside a box, |
| 27 | + // we will charge neither the outer type nor the environment |
| 28 | + } |
| 29 | + |
| 30 | + val test3 = { |
| 31 | + type Box[X] = X |
| 32 | + type Id[X] = Box[X] -> Unit |
| 33 | + type Op[X] = Unit -> Box[X] |
| 34 | + val f: Unit -> ({io} Cap) -> Unit = ??? |
| 35 | + val g: Op[{fs} Id[{io} Cap]] = f // error |
| 36 | + val h: {} Op[{io} Id[{io} Cap]] = f |
| 37 | + } |
| 38 | +} |
0 commit comments