Skip to content

Commit 410a777

Browse files
committed
Update mutatibility status only in open VarStates
1 parent d1d4700 commit 410a777

File tree

10 files changed

+55
-13
lines changed

10 files changed

+55
-13
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureSet.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ sealed abstract class CaptureSet extends Showable:
297297
/** The subcapturing test, using a given VarState */
298298
final def subCaptures(that: CaptureSet)(using ctx: Context, vs: VarState = VarState()): Boolean =
299299
TypeComparer.inNestedLevel:
300-
val this1 = this.adaptMutability(that)
300+
val this1 = if vs.isOpen then this.adaptMutability(that) else this
301301
if this1 == null then false
302302
else if this1 ne this then
303303
capt.println(i"WIDEN ro $this with ${this.mutability} <:< $that with ${that.mutability} to $this1")

tests/neg-custom-args/captures/linear-buffer.check

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/linear-buffer.scala:7:29 ---------------------------------
2-
7 | def bar: BadBuffer[T]^ = this // error
2+
7 | def bar: BadBuffer[T]^ = this // error // error separation
33
| ^^^^
44
| Found: BadBuffer[T]^{BadBuffer.this.rd}
55
| Required: BadBuffer[T]^
@@ -15,6 +15,11 @@
1515
| ^^^^^^^^^^^^^
1616
| Separation failure: method append's result type BadBuffer[T]^ hides non-local this of class class BadBuffer.
1717
| The access must be in a consume method to allow this.
18+
-- Error: tests/neg-custom-args/captures/linear-buffer.scala:7:13 ------------------------------------------------------
19+
7 | def bar: BadBuffer[T]^ = this // error // error separation
20+
| ^^^^^^^^^^^^^
21+
| Separation failure: method bar's result type BadBuffer[T]^ hides non-local this of class class BadBuffer.
22+
| The access must be in a consume method to allow this.
1823
-- Error: tests/neg-custom-args/captures/linear-buffer.scala:10:29 -----------------------------------------------------
1924
10 | def bar: BadBuffer[T]^ = this // error // error
2025
| ^^^^

tests/neg-custom-args/captures/linear-buffer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import language.experimental.captureChecking
44
class BadBuffer[T] extends Mutable:
55
update def append(x: T): BadBuffer[T]^ = this // error
66
def foo =
7-
def bar: BadBuffer[T]^ = this // error
7+
def bar: BadBuffer[T]^ = this // error // error separation
88
bar
99
update def updateFoo =
1010
def bar: BadBuffer[T]^ = this // error // error

tests/neg-custom-args/captures/mutability.check

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| Cannot call update method set of self
1010
| since its capture set {self} is read-only.
1111
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/mutability.scala:10:25 -----------------------------------
12-
10 | val self2: Ref[T]^ = this // error
12+
10 | val self2: Ref[T]^ = this // error // error separation
1313
| ^^^^
1414
| Found: Ref[T]^{Ref.this.rd}
1515
| Required: Ref[T]^
@@ -58,7 +58,7 @@
5858
| Cannot call update method set of Ref[T^{}]^{Ref.this.rd}
5959
| since its capture set {Ref.this.rd} of method self5 is read-only.
6060
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/mutability.scala:20:27 -----------------------------------
61-
20 | def self6(): Ref[T]^ = this // error
61+
20 | def self6(): Ref[T]^ = this // error // error separation
6262
| ^^^^
6363
| Found: Ref[T]^{Ref.this.rd}
6464
| Required: Ref[T]^
@@ -109,3 +109,13 @@
109109
| ^^^^^^^^^^
110110
| Cannot call update method set of Ref[Int]^{r6*.rd}
111111
| since its capture set {r6*.rd} is read-only.
112+
-- Error: tests/neg-custom-args/captures/mutability.scala:10:15 --------------------------------------------------------
113+
10 | val self2: Ref[T]^ = this // error // error separation
114+
| ^^^^^^^
115+
| Separation failure: value self2's type Ref[T]^ hides non-local this of class class Ref.
116+
| The access must be in a consume method to allow this.
117+
-- Error: tests/neg-custom-args/captures/mutability.scala:20:17 --------------------------------------------------------
118+
20 | def self6(): Ref[T]^ = this // error // error separation
119+
| ^^^^^^^
120+
| Separation failure: method self6's result type Ref[T]^ hides non-local this of class class Ref.
121+
| The access must be in a consume method to allow this.

tests/neg-custom-args/captures/mutability.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Ref[T](init: T) extends caps.Mutable:
77
def sneakyHide(x: T) =
88
val self = this
99
self.set(x) // error
10-
val self2: Ref[T]^ = this // error
10+
val self2: Ref[T]^ = this // error // error separation
1111
self2.set(x) // error
1212

1313
val self3 = () => this
@@ -17,7 +17,7 @@ class Ref[T](init: T) extends caps.Mutable:
1717

1818
def self5() = this
1919
self5().set(x) // error
20-
def self6(): Ref[T]^ = this // error
20+
def self6(): Ref[T]^ = this // error // error separation
2121
self6().set(x) // error
2222

2323
class Ref2[T](init: T) extends caps.Mutable:

tests/neg-custom-args/captures/mutvars.check

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| Cannot assign to field fld of self
1010
| since its capture set {self} is read-only.
1111
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/mutvars.scala:9:25 ---------------------------------------
12-
9 | val self2: Ref[T]^ = this // error
12+
9 | val self2: Ref[T]^ = this // error // error separation
1313
| ^^^^
1414
| Found: Ref[T]^{Ref.this.rd}
1515
| Required: Ref[T]^
@@ -44,7 +44,7 @@
4444
| Cannot assign to field fld of Ref[T^{}]^{Ref.this.rd}
4545
| since its capture set {Ref.this.rd} of method self5 is read-only.
4646
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/mutvars.scala:19:27 --------------------------------------
47-
19 | def self6(): Ref[T]^ = this // error
47+
19 | def self6(): Ref[T]^ = this // error // error separation
4848
| ^^^^
4949
| Found: Ref[T]^{Ref.this.rd}
5050
| Required: Ref[T]^
@@ -88,3 +88,13 @@
8888
| ^^^^^^^^^^^^^^^
8989
| Cannot assign to field fld of Ref[Int]^{r6*.rd}
9090
| since its capture set {r6*.rd} is read-only.
91+
-- Error: tests/neg-custom-args/captures/mutvars.scala:9:15 ------------------------------------------------------------
92+
9 | val self2: Ref[T]^ = this // error // error separation
93+
| ^^^^^^^
94+
| Separation failure: value self2's type Ref[T]^ hides non-local this of class class Ref.
95+
| The access must be in a consume method to allow this.
96+
-- Error: tests/neg-custom-args/captures/mutvars.scala:19:17 -----------------------------------------------------------
97+
19 | def self6(): Ref[T]^ = this // error // error separation
98+
| ^^^^^^^
99+
| Separation failure: method self6's result type Ref[T]^ hides non-local this of class class Ref.
100+
| The access must be in a consume method to allow this.

tests/neg-custom-args/captures/mutvars.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Ref[T](init: T) extends caps.Mutable:
66
def sneakyHide(x: T) =
77
val self = this
88
self.fld = x // error
9-
val self2: Ref[T]^ = this // error
9+
val self2: Ref[T]^ = this // error // error separation
1010
self2.fld = x
1111

1212
val self3 = () => this
@@ -16,7 +16,7 @@ class Ref[T](init: T) extends caps.Mutable:
1616

1717
def self5() = this
1818
self5().fld = x // error
19-
def self6(): Ref[T]^ = this // error
19+
def self6(): Ref[T]^ = this // error // error separation
2020
self6().fld = x
2121

2222
class Ref2[T](init: T) extends caps.Mutable:

tests/neg-custom-args/captures/ro-mut-conformance.check

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,22 @@
44
| Cannot call update method set of a
55
| since its capture set {a} is read-only.
66
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/ro-mut-conformance.scala:12:21 ---------------------------
7-
12 | val t: Ref^{cap} = a // error
7+
12 | val t: Ref^{cap} = a // error // error separation
88
| ^
99
| Found: (a : Ref)
1010
| Required: Ref^
1111
|
1212
| Note that {cap} is an exclusive capture set of the mutable type Ref^,
1313
| it cannot subsume a read-only capture set of the mutable type (a : Ref).
1414
|
15+
| Note that capability cap².rd is not included in capture set {cap}.
16+
|
1517
| where: ^ and cap refer to a fresh root capability in the type of value t
18+
| cap² is a fresh root capability in the type of parameter a
1619
|
1720
| longer explanation available when compiling with `-explain`
21+
-- Error: tests/neg-custom-args/captures/ro-mut-conformance.scala:12:9 -------------------------------------------------
22+
12 | val t: Ref^{cap} = a // error // error separation
23+
| ^^^^^^^^^
24+
| Separation failure: value t's type Ref^ hides parameter a.
25+
| The parameter needs to be annotated with consume to allow this.

tests/neg-custom-args/captures/ro-mut-conformance.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Ref extends IRef, Mutable:
99
def test1(a: Ref^{cap.rd}): Unit =
1010
a.set(42) // error
1111
def test2(a: Ref^{cap.rd}): Unit =
12-
val t: Ref^{cap} = a // error
12+
val t: Ref^{cap} = a // error // error separation
1313
def b: Ref^{cap.rd} = ???
1414
val i: IRef^{cap} = b // ok, no added privilege from `cap` on an IRef
1515
t.set(42)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import caps.*
2+
class C extends SharedCapability
3+
4+
def foo(consume x: C): C = x
5+
6+
def test(consume x: C) =
7+
val y: C = C()
8+
foo(x)
9+
foo(y)

0 commit comments

Comments
 (0)