Skip to content

Commit b0e25eb

Browse files
committed
Don't improve according to VAR rule for reach-caps
We used to improve c.x if type Box[T^{cs}] to c.x*. But this risks getting a follow-on error that a usage leaks into an enclosing method. For instance, if we have def foo(c: Box[T^{io}]) = println(c.x) we want to leave the capset of `c.x` as `{io}` instead of improving to `c.x*` and running into an error later.
1 parent 11c2d53 commit b0e25eb

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,11 +1581,9 @@ class CheckCaptures extends Recheck, SymTransformer:
15811581
private def improveCaptures(widened: Type, prefix: Type)(using Context): Type = prefix match
15821582
case ref: Capability if ref.isTracked =>
15831583
widened match
1584-
case widened @ CapturingType(p, refs) if ref.singletonCaptureSet.mightSubcapture(refs) =>
1585-
val improvedCs =
1586-
if widened.isBoxed then ref.reach.singletonCaptureSet
1587-
else ref.singletonCaptureSet
1588-
widened.derivedCapturingType(p, improvedCs)
1584+
case widened @ CapturingType(p, refs)
1585+
if ref.singletonCaptureSet.mightSubcapture(refs) && !widened.isBoxed =>
1586+
widened.derivedCapturingType(p, ref.singletonCaptureSet)
15891587
.showing(i"improve $widened to $result", capt)
15901588
case _ => widened
15911589
case _ => widened
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
-- Error: tests/neg-custom-args/captures/sep-box.scala:41:9 ------------------------------------------------------------
22
41 | par(h1.value, h2.value) // error
33
| ^^^^^^^^
4-
|Separation failure: argument of type Ref^{h1.value*}
4+
|Separation failure: argument of type Ref^{xs*}
55
|to method par: (x: Ref^, y: Ref^): Unit
66
|corresponds to capture-polymorphic formal parameter x of type Ref^
7-
|and hides capabilities {h1.value*}.
8-
|Some of these overlap with the captures of the second argument with type Ref^{h2.value*}.
7+
|and hides capabilities {xs*}.
8+
|Some of these overlap with the captures of the second argument with type Ref^{xs*}.
99
|
10-
| Hidden set of current argument : {h1.value*}
11-
| Hidden footprint of current argument : {h1.value*, xs*}
12-
| Capture set of second argument : {h2.value*}
13-
| Footprint set of second argument : {h2.value*, xs*}
10+
| Hidden set of current argument : {xs*}
11+
| Hidden footprint of current argument : {xs*}
12+
| Capture set of second argument : {xs*}
13+
| Footprint set of second argument : {xs*}
1414
| The two sets overlap at : {xs*}
1515
|
1616
|where: ^ refers to a fresh root capability classified as Mutable created in method test when checking argument to parameter x of method par

0 commit comments

Comments
 (0)