Skip to content

Commit 0b65d39

Browse files
committed
Fix spurious redundant capability warnings
1 parent 5c51b7b commit 0b65d39

File tree

4 files changed

+39
-27
lines changed

4 files changed

+39
-27
lines changed

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -936,21 +936,24 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
936936
if others.accountsFor(ref) then
937937
report.warning(em"redundant capture: $dom already accounts for $ref", pos)
938938

939-
if ref.captureSetOfInfo.elems.isEmpty
940-
&& !ref.coreType.derivesFrom(defn.Caps_Capability)
941-
&& !ref.coreType.derivesFrom(defn.Caps_CapSet) then
942-
val deepStr = if ref.isReach then " deep" else ""
943-
report.error(em"$ref cannot be tracked since its$deepStr capture set is empty", pos)
944-
check(parent.captureSet, parent)
945-
946-
val others =
947-
for
948-
j <- 0 until retained.length if j != i
949-
r = retained(j)
950-
if !r.isTerminalCapability
951-
yield r
952-
val remaining = CaptureSet(others*)
953-
check(remaining, remaining)
939+
if !ref.coreType.derivesFrom(defn.Caps_Capability)
940+
// Capability classes don't have their implied capture set yet, so
941+
// they would be seen as pure
942+
&& !ref.coreType.derivesFrom(defn.Caps_CapSet)
943+
then
944+
if ref.captureSetOfInfo.elems.isEmpty then
945+
val deepStr = if ref.isReach then " deep" else ""
946+
report.error(em"$ref cannot be tracked since its$deepStr capture set is empty", pos)
947+
check(parent.captureSet, parent)
948+
949+
val others =
950+
for
951+
j <- 0 until retained.length if j != i
952+
r = retained(j)
953+
if !r.isTerminalCapability
954+
yield r
955+
val remaining = CaptureSet(others*)
956+
check(remaining, remaining)
954957
end for
955958
catch case ex: IllegalCaptureRef =>
956959
report.error(em"Illegal capture reference: ${ex.getMessage}", tpt.srcPos)

tests/neg-custom-args/captures/filevar.check

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,3 @@
1212
18 | o.log
1313
|
1414
| longer explanation available when compiling with `-explain`
15-
-- Warning: tests/neg-custom-args/captures/filevar.scala:11:55 ---------------------------------------------------------
16-
11 |def withFile[T](op: (l: caps.Capability) ?-> (f: File^{l}) => T): T =
17-
| ^
18-
| redundant capture: File already accounts for (l : scala.caps.Capability)

tests/neg-custom-args/captures/i15923.check

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,3 @@
2020
|where: => refers to a fresh root capability created in anonymous function of type (using lcap: scala.caps.Capability): Cap^{lcap} -> Id[Cap] when instantiating expected result type Cap^{lcap} ->{cap²} Id[Cap^'s13]^'s14 of function literal
2121
|
2222
| longer explanation available when compiling with `-explain`
23-
-- Warning: tests/neg-custom-args/captures/i15923.scala:21:56 ----------------------------------------------------------
24-
21 | def withCap[X](op: (lcap: caps.Capability) ?-> Cap^{lcap} => X): X = {
25-
| ^^^^
26-
| redundant capture: test2.Cap already accounts for (lcap : scala.caps.Capability)
27-
-- Warning: tests/neg-custom-args/captures/i15923.scala:6:54 -----------------------------------------------------------
28-
6 | def withCap[X](op: (lcap: caps.Capability) ?-> Cap^{lcap} => X): X = {
29-
| ^^^^
30-
| redundant capture: Cap already accounts for (lcap : scala.caps.Capability)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//> using options -Werror
2+
import caps.*
3+
4+
trait State[A] extends SharedCapability:
5+
def get: A
6+
def set(a: A): Unit
7+
8+
def get[A]: State[A] ?-> A = s ?=> s.get
9+
def set[A](a: A): State[A] ?-> Unit = s ?=> s.set(a)
10+
11+
trait Rand:
12+
def range(min: Int, max: Int): Int
13+
14+
object Rand:
15+
def fromState: (s: State[Long]) ?-> Rand^{s} =
16+
new Rand:
17+
override def range(min: Int, max: Int): Int =
18+
val seed = get
19+
val (nextSeed, next) = (seed + 1, seed.toInt) // obviously wrong, but not the point...
20+
set(nextSeed)
21+
next

0 commit comments

Comments
 (0)