Skip to content

Commit eaccea3

Browse files
committed
Don't treat non-capturechecked classes are pure.
If they have a self type, it would not mention a capture set anyway.
1 parent a6624de commit eaccea3

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,11 @@ extension (cls: ClassSymbol)
256256
def pureBaseClass(using Context): Option[Symbol] =
257257
cls.baseClasses.find: bc =>
258258
defn.pureBaseClasses.contains(bc)
259-
|| bc.givenSelfType.dealiasKeepAnnots.match
260-
case CapturingType(_, refs) => refs.isAlwaysEmpty
261-
case RetainingType(_, refs) => refs.isEmpty
262-
case selfType => selfType.exists && selfType.captureSet.isAlwaysEmpty
259+
|| bc.is(CaptureChecked)
260+
&& bc.givenSelfType.dealiasKeepAnnots.match
261+
case CapturingType(_, refs) => refs.isAlwaysEmpty
262+
case RetainingType(_, refs) => refs.isEmpty
263+
case selfType => selfType.exists && selfType.captureSet.isAlwaysEmpty
263264

264265
extension (sym: Symbol)
265266

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
-- Error: tests/neg-custom-args/captures/leaked-curried.scala:13:20 ----------------------------------------------------
2-
13 | () => () => io // error
1+
-- Error: tests/neg-custom-args/captures/leaked-curried.scala:14:20 ----------------------------------------------------
2+
14 | () => () => io // error
33
| ^^
4-
|(io : Cap^) cannot be referenced here; it is not included in the allowed capture set {} of pure base class trait Pure
4+
|(io : Cap^) cannot be referenced here; it is not included in the allowed capture set {} of the self type of class Fuzz
5+
-- [E058] Type Mismatch Error: tests/neg-custom-args/captures/leaked-curried.scala:15:10 -------------------------------
6+
15 | class Foo extends Box, Pure: // error
7+
| ^
8+
| illegal inheritance: self type Foo^{io} of class Foo does not conform to self type Pure
9+
| of parent trait Pure
10+
|
11+
| longer explanation available when compiling with `-explain`

tests/neg-custom-args/captures/leaked-curried.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ trait Box:
88

99
def main(): Unit =
1010
val leaked = withCap: (io: Cap^) =>
11-
class Foo extends Box, Pure:
11+
class Fuzz extends Box, Pure:
12+
self =>
1213
val get: () ->{} () ->{io} Cap^ =
1314
() => () => io // error
15+
class Foo extends Box, Pure: // error
16+
val get: () ->{} () ->{io} Cap^ =
17+
() => () => io
1418
new Foo
1519
val bad = leaked.get()().use() // using a leaked capability

tests/neg-custom-args/captures/outer-var.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
16 | var finalizeActions = collection.mutable.ListBuffer[() => Unit]() // error
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3838
| Found: scala.collection.mutable.ListBuffer[box () => Unit]
39-
| Required: scala.collection.mutable.ListBuffer[box () ->? Unit]
39+
| Required: scala.collection.mutable.ListBuffer[box () ->? Unit]^?
4040
|
4141
| Note that the universal capability `cap`
4242
| cannot be included in capture set ? of variable finalizeActions

0 commit comments

Comments
 (0)