Skip to content

Commit f98c961

Browse files
committed
Fix default self types of capabilities
They still were read-only, but all Capabilities implicitly capture `cap` now.
1 parent 3da7bb1 commit f98c961

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,9 +689,9 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
689689
// neither pure, nor are publicily extensible with an unconstrained self type.
690690
val cs = CaptureSet.ProperVar(cls, CaptureSet.emptyRefs, nestedOK = false, isRefining = false)
691691
if cls.derivesFrom(defn.Caps_Capability) then
692-
// If cls is a capability class, we need to add a fresh readonly capability to
693-
// ensure we cannot treat the class as pure.
694-
CaptureSet.fresh(cls, cls.thisType, Origin.InDecl(cls)).readOnly.subCaptures(cs)
692+
// If cls is a capability class, we need to add a fresh capability to ensure
693+
// we cannot treat the class as pure.
694+
CaptureSet.fresh(cls, cls.thisType, Origin.InDecl(cls)).subCaptures(cs)
695695
CapturingType(cinfo.selfType, cs)
696696

697697
// Compute new parent types

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33
| ^^^^^^^^^^^^^
44
| Separation failure: method append's result type BadBuffer[T]^ hides non-local this of class class BadBuffer.
55
| The access must be in a consume method to allow this.
6+
-- Error: tests/neg-custom-args/captures/linear-buffer.scala:7:29 ------------------------------------------------------
7+
7 | def bar: BadBuffer[T]^ = this // error // error
8+
| ^^^^
9+
| Separation failure: Illegal access to {BadBuffer.this} which is hidden by the previous definition
10+
| of method append with result type BadBuffer[T]^.
11+
| This type hides capabilities {BadBuffer.this}
12+
|
13+
| where: ^ refers to a fresh root capability classified as Mutable in the result type of method append
614
-- Error: tests/neg-custom-args/captures/linear-buffer.scala:7:13 ------------------------------------------------------
7-
7 | def bar: BadBuffer[T]^ = this // error
15+
7 | def bar: BadBuffer[T]^ = this // error // error
816
| ^^^^^^^^^^^^^
917
| Separation failure: method bar's result type BadBuffer[T]^ hides non-local this of class class BadBuffer.
1018
| The access must be in a consume method to allow this.

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
88
bar
99

1010
class Buffer[T] extends Mutable:

0 commit comments

Comments
 (0)