File tree Expand file tree Collapse file tree 4 files changed +17
-12
lines changed
compiler/src/dotty/tools/dotc/cc
tests/neg-custom-args/captures Expand file tree Collapse file tree 4 files changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -78,18 +78,22 @@ extension (tree: Tree)
78
78
79
79
extension (tp : Type )
80
80
81
- def retainedElements (using Context ): List [CaptureRef ] = tp match
81
+ def retainedElementsRaw (using Context ): List [Type ] = tp match
82
82
case ReachCapability (tp1) =>
83
83
tp1.reach :: Nil
84
84
case ReadOnlyCapability (tp1) =>
85
85
tp1.readOnly :: Nil
86
- case tp : CaptureRef =>
86
+ case OrType (tp1, tp2) =>
87
+ tp1.retainedElementsRaw ++ tp2.retainedElementsRaw
88
+ case tp =>
89
+ // Nothing is a special type to represent the empty set
87
90
if tp.isNothingType then Nil
88
91
else tp :: Nil // should be checked by wellformedness
89
- case OrType (tp1, tp2) =>
90
- tp1.retainedElements ++ tp2.retainedElements
91
- case _ =>
92
- throw IllegalCaptureRef (tp)
92
+
93
+ def retainedElements (using Context ): List [CaptureRef ] =
94
+ retainedElementsRaw.map:
95
+ case tp : CaptureRef => tp
96
+ case tp => throw IllegalCaptureRef (tp)
93
97
94
98
/** Is this type a CaptureRef that can be tracked?
95
99
* This is true for
Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ object CheckCaptures:
105
105
report.error(em " $elem cannot be tracked since it is not a parameter or local value " , pos)
106
106
case tpe =>
107
107
report.error(em " $elem: $tpe is not a legal element of a capture set " , pos)
108
- for elem <- ann.retainedSet.retainedElements do
108
+ for elem <- ann.retainedSet.retainedElementsRaw do
109
109
elem match
110
110
case ref : TypeRef =>
111
111
val refSym = ref.symbol
Original file line number Diff line number Diff line change 55
55
| longer explanation available when compiling with `-explain`
56
56
-- Error: tests/neg-custom-args/captures/capt1.scala:38:13 -------------------------------------------------------------
57
57
38 | val z3 = h[(() -> Cap) @retains[x.type]](() => x)(() => C()) // error
58
- | ^^^^^^^^^^^^^^^^^^^^^^^
58
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
59
59
| Type variable X of method h cannot be instantiated to box () ->{x} C^ since
60
60
| the part C^ of that type captures the root capability `cap`.
61
61
|
Original file line number Diff line number Diff line change
1
+ import language .experimental .captureChecking
1
2
import caps .*
2
3
3
4
trait AbstractWrong :
4
5
type C <: CapSet
5
6
def f (): Unit ^ {C } // error
6
7
7
8
trait Abstract1 :
8
- type C >: CapSet <: CapSet ^
9
+ type C >: CapSet <: CapSet ^ // error
9
10
def f (): Unit ^ {C }
10
11
11
- // class Abstract2:
12
- // type C^
13
- // def f(): Unit^{C^ }
12
+ trait Abstract2 :
13
+ type C <: {cap}
14
+ def f (): Unit ^ {C }
You can’t perform that action at this time.
0 commit comments