Skip to content

Commit 3bc3d2f

Browse files
committed
Tweak HiddenSet
Avoid var for owningCap
1 parent cbd308a commit 3bc3d2f

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ object Capabilities:
138138
* for diagnostics
139139
*/
140140
case class FreshCap private (owner: Symbol, origin: Origin)(using @constructorOnly ctx: Context) extends RootCapability:
141-
val hiddenSet = CaptureSet.HiddenSet(owner)
142-
hiddenSet.owningCap = this
141+
val hiddenSet = CaptureSet.HiddenSet(owner, this: @unchecked)
142+
// fails initialization check without the @unchecked
143143

144144
override def equals(that: Any) = that match
145145
case that: FreshCap => this eq that

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -950,16 +950,15 @@ object CaptureSet:
950950
* which are already subject through snapshotting and rollbacks in VarState.
951951
* It's advantageous if we don't need to deal with other pieces of state there.
952952
*/
953-
class HiddenSet(initialOwner: Symbol)(using @constructorOnly ictx: Context)
953+
class HiddenSet(initialOwner: Symbol, val owningCap: FreshCap)(using @constructorOnly ictx: Context)
954954
extends Var(initialOwner):
955-
var owningCap: FreshCap = uninitialized // initialized when owning FreshCap is created
956955
var givenOwner: Symbol = initialOwner
957956

958957
override def owner = givenOwner
959958

960-
//assert(id != 4)
959+
//assert(id != 3)
961960

962-
description = i"elements subsumed by $owningCap"
961+
description = i"of elements subsumed by a fresh cap in $initialOwner"
963962

964963
private def aliasRef: FreshCap | Null =
965964
if myElems.size == 1 then
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/scope-extrude-mut.scala:9:8 ------------------------------
2+
9 | a = a1 // error
3+
| ^^
4+
| Found: A^{a1.rd}
5+
| Required: A^
6+
|
7+
| where: ^ refers to a fresh root capability in the type of variable a
8+
|
9+
| longer explanation available when compiling with `-explain`
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import language.experimental.captureChecking
2+
3+
class A extends caps.Mutable
4+
5+
class B:
6+
private var a: A^ = A()
7+
def b() =
8+
val a1 = A()
9+
a = a1 // error

0 commit comments

Comments
 (0)