Skip to content

Commit e5729a0

Browse files
committed
Don't avoid elements of hidden sets
It fixes one of the problems in sep-pairs. It probably won't matter anymore for correctness once we revise overlap calculations, but it will give better error messages.
1 parent f41a94a commit e5729a0

File tree

3 files changed

+48
-27
lines changed

3 files changed

+48
-27
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import typer.ErrorReporting.Addenda
1717
import util.common.alwaysTrue
1818
import scala.collection.{mutable, immutable}
1919
import CCState.*
20+
import TypeOps.AvoidMap
2021

2122
/** A class for capture sets. Capture sets can be constants or variables.
2223
* Capture sets support inclusion constraints <:< where <:< is subcapturing.
@@ -329,6 +330,8 @@ sealed abstract class CaptureSet extends Showable:
329330
else BiMapped(asVar, tm, mappedElems)
330331
case tm: IdentityCaptRefMap =>
331332
this
333+
case tm: AvoidMap if this.isInstanceOf[HiddenSet] =>
334+
this
332335
case _ =>
333336
val mapped = mapRefs(elems, tm, tm.variance)
334337
if isConst then
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import caps.Mutable
2+
import caps.cap
3+
4+
class Ref extends Mutable:
5+
var x = 0
6+
def get: Int = x
7+
mut def put(y: Int): Unit = x = y
8+
9+
class Pair[+X, +Y](val fst: X, val snd: Y)
10+
11+
def mkPair[X](x: X): Pair[X, X] = Pair(x, x)
12+
13+
def bad: Pair[Ref^, Ref^] = // error: overlap at r1*, r0
14+
val r0 = Ref()
15+
val r1: Pair[Ref^, Ref^] = mkPair(r0) // error: overlap at r0
16+
r1
17+
18+
class SamePair[+X](val fst: X, val snd: X)
19+
20+
def twoRefs(): Pair[Ref^, Ref^] =
21+
val r1 = Ref()
22+
val r2 = Ref()
23+
Pair(r1, r2)
24+
25+
def twoRefs2(): SamePair[Ref^] =
26+
val r1 = Ref()
27+
val r2 = Ref()
28+
val r3: SamePair[Ref^] = SamePair(r1, r1) // ok
29+
r3
30+
31+
def twoRefsBad(): Pair[Ref^, Ref^] =
32+
Pair(Ref(), Ref()) // error // error: universal capability cannot be included in capture set
33+
// but should work since this is morally equivalent to `twoRefs`
34+
35+
def test(io: Object^): Unit =
36+
val two = twoRefs()
37+
val fst: Ref^{two.fst*} = two.fst
38+
val snd: Ref^{two.snd*} = two.snd
39+
40+
val two2 = twoRefs2()
41+
val fst2 = two.fst
42+
val snd2 = two.snd
43+
44+
val p2: Pair[Ref^, Ref^] = Pair(fst, snd) // should be error
45+

tests/pos-custom-args/captures/sep-pairs.scala

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)