Skip to content

Commit

Permalink
Add sealed refs test and fix check files of other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Nov 4, 2023
1 parent f4066c0 commit e22744d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/neg-custom-args/captures/cc-this.check
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
-- Error: tests/neg-custom-args/captures/cc-this.scala:17:8 ------------------------------------------------------------
17 | class C4(val f: () => Int) extends C3 // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| reference (C4.this.f : () => Int) is not included in the allowed capture set {} of pure base class class C3
|reference (C4.this.f : () => Int) captured by this self type is not included in the allowed capture set {} of pure base class class C3
14 changes: 10 additions & 4 deletions tests/neg-custom-args/captures/cc-this2.check
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@

-- Error: tests/neg-custom-args/captures/cc-this2/D_2.scala:2:6 --------------------------------------------------------
-- Error: tests/neg-custom-args/captures/cc-this2/D_2.scala:3:8 --------------------------------------------------------
3 | this: D^ => // error
| ^^
|reference (caps.cap : caps.Cap) captured by this self type is not included in the allowed capture set {} of pure base class class C
-- [E058] Type Mismatch Error: tests/neg-custom-args/captures/cc-this2/D_2.scala:2:6 -----------------------------------
2 |class D extends C: // error
|^
|reference (caps.cap : caps.Cap) is not included in the allowed capture set {} of pure base class class C
3 | this: D^ =>
| ^
| illegal inheritance: self type D^ of class D does not conform to self type C
| of parent class C
|
| longer explanation available when compiling with `-explain`
2 changes: 1 addition & 1 deletion tests/neg-custom-args/captures/cc-this2/D_2.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

class D extends C: // error
this: D^ =>
this: D^ => // error
9 changes: 4 additions & 5 deletions tests/neg-custom-args/captures/exception-definitions.check
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
-- Error: tests/neg-custom-args/captures/exception-definitions.scala:2:6 -----------------------------------------------
2 |class Err extends Exception: // error
|^
|reference (caps.cap : caps.Cap) is not included in the allowed capture set {} of pure base class class Throwable
3 | self: Err^ =>
-- Error: tests/neg-custom-args/captures/exception-definitions.scala:3:8 -----------------------------------------------
3 | self: Err^ => // error
| ^^^^
|reference (caps.cap : caps.Cap) captured by this self type is not included in the allowed capture set {} of pure base class class Throwable
-- Error: tests/neg-custom-args/captures/exception-definitions.scala:7:12 ----------------------------------------------
7 | val x = c // error
| ^
Expand Down
4 changes: 2 additions & 2 deletions tests/neg-custom-args/captures/exception-definitions.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

class Err extends Exception: // error
self: Err^ =>
class Err extends Exception:
self: Err^ => // error

def test(c: Any^) =
class Err2 extends Exception:
Expand Down
42 changes: 42 additions & 0 deletions tests/neg-custom-args/captures/sealed-refs.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class Ref[sealed A](init: A):
this: Ref[A]^ =>
private var x: A = init
def get: A = x
def set(x: A): Unit = this.x = x

class It[X]:
this: It[X]^ =>

def f1[B1](x: B1, next: B1 -> B1) =
var r = x // ok
r = next(x)
r

def f2[B2](x: B2, next: B2 -> B2) =
val r = Ref[B2](x) // error
r.set(next(x))
r.get

def g[sealed B](x: B, next: B -> B) =
val r = Ref[B](x) // ok
r.set(next(x))
r.get

import annotation.unchecked.uncheckedCaptures

def h[B](x: B, next: B -> B) =
val r = Ref[B @uncheckedCaptures](x) // ok
r.set(next(x))
r.get

def f3[B](x: B, next: B -> B) =
val r: Ref[B^{cap[f3]}] = Ref[B^{cap[f3]}](x) // error
r.set(next(x))
val y = r.get
()

def f4[B](x: B, next: B -> B) =
val r: Ref[B]^{cap[f4]} = Ref[B](x) // error
r.set(next(x))
val y = r.get
()

0 comments on commit e22744d

Please sign in to comment.