File tree Expand file tree Collapse file tree 3 files changed +48
-27
lines changed
compiler/src/dotty/tools/dotc/cc Expand file tree Collapse file tree 3 files changed +48
-27
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import typer.ErrorReporting.Addenda
17
17
import util .common .alwaysTrue
18
18
import scala .collection .{mutable , immutable }
19
19
import CCState .*
20
+ import TypeOps .AvoidMap
20
21
21
22
/** A class for capture sets. Capture sets can be constants or variables.
22
23
* Capture sets support inclusion constraints <:< where <:< is subcapturing.
@@ -329,6 +330,8 @@ sealed abstract class CaptureSet extends Showable:
329
330
else BiMapped (asVar, tm, mappedElems)
330
331
case tm : IdentityCaptRefMap =>
331
332
this
333
+ case tm : AvoidMap if this .isInstanceOf [HiddenSet ] =>
334
+ this
332
335
case _ =>
333
336
val mapped = mapRefs(elems, tm, tm.variance)
334
337
if isConst then
Original file line number Diff line number Diff line change
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
+
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments