-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Coarse restriction to disallow local roots in external types
This needs to be refined further for class members, similar to how we check that private types cannot escape from a class API.
- Loading branch information
Showing
8 changed files
with
83 additions
and
4 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
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,12 @@ | ||
-- Error: tests/neg-custom-args/captures/localcaps.scala:4:12 ---------------------------------------------------------- | ||
4 | def x: C^{cap[d]} = ??? // error | ||
| ^^^^^^ | ||
| `d` does not name an outer definition that represents a capture level | ||
-- Error: tests/neg-custom-args/captures/localcaps.scala:9:47 ---------------------------------------------------------- | ||
9 | private val z2 = identity((x: Int) => (c: C^{cap[z2]}) => x) // error | ||
| ^^^^^^^ | ||
| `z2` does not name an outer definition that represents a capture level | ||
-- Error: tests/neg-custom-args/captures/localcaps.scala:6:6 ----------------------------------------------------------- | ||
6 | def y: C^{cap[C]} = ??? // error | ||
| ^ | ||
| local root (cap[C] : caps.Cap) cannot appear in type of class C |
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
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
22 changes: 22 additions & 0 deletions
22
tests/neg-custom-args/captures/recursive-leaking-local-cap.scala
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,22 @@ | ||
import language.experimental.captureChecking | ||
trait Cap: | ||
def use: Int = 42 | ||
|
||
def usingCap[sealed T](op: Cap^ => T): T = ??? | ||
|
||
def badTest(): Unit = | ||
def bad(b: Boolean)(c: Cap^): Cap^{cap[bad]} = // error | ||
if b then c | ||
else | ||
val leaked = usingCap[Cap^{cap[bad]}](bad(true)) | ||
leaked.use // boom | ||
c | ||
|
||
usingCap[Unit]: c0 => | ||
bad(false)(c0) | ||
|
||
class Bad: | ||
def foo: Cap^{cap[Bad]} = ??? // error | ||
private def bar: Cap^{cap[Bad]} = ??? // ok | ||
|
||
|
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,21 @@ | ||
abstract class C1[A1]: | ||
def set(x: A1): Unit | ||
def get: A1 | ||
|
||
trait Co[+A]: | ||
def get: A | ||
|
||
class C2[sealed A2] extends C1[A2], Co[A2]: // ok | ||
private var x: A2 = ??? | ||
def set(x: A2): Unit = | ||
this.x = x | ||
def get: A2 = x | ||
|
||
class C3[A3] extends C2[A3] // error | ||
|
||
abstract class C4[sealed A4] extends Co[A4] // ok | ||
|
||
abstract class C5[sealed +A5] extends Co[A5] // ok | ||
|
||
abstract class C6[A6] extends C5[A6] // error | ||
|