Skip to content

Commit

Permalink
Patch pure base classes for FunctionN
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Oct 19, 2023
1 parent 272d53c commit 8d7a901
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/cc/CaptureOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ extension (cls: ClassSymbol)
def pureBaseClass(using Context): Option[Symbol] =
cls.baseClasses.find: bc =>
defn.pureBaseClasses.contains(bc)
|| bc.givenSelfType.dealiasKeepAnnots.match
|| bc.is(CaptureChecked)
&& bc.givenSelfType.dealiasKeepAnnots.match
case CapturingType(_, refs) => refs.isAlwaysEmpty
case RetainingType(_, refs) => refs.isEmpty
case selfType => selfType.exists && selfType.captureSet.isAlwaysEmpty
Expand Down
6 changes: 3 additions & 3 deletions tests/neg-custom-args/captures/leaked-curried.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Error: tests/neg-custom-args/captures/leaked-curried.scala:13:20 ----------------------------------------------------
13 | () => () => io // error
-- Error: tests/neg-custom-args/captures/leaked-curried.scala:14:20 ----------------------------------------------------
14 | () => () => io // error
| ^^
|(io : Cap^) cannot be referenced here; it is not included in the allowed capture set {} of pure base class trait Pure
|(io : Cap^) cannot be referenced here; it is not included in the allowed capture set {} of the self type of class Foo
1 change: 1 addition & 0 deletions tests/neg-custom-args/captures/leaked-curried.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ trait Box:
def main(): Unit =
val leaked = withCap: (io: Cap^) =>
class Foo extends Box, Pure:
self =>
val get: () ->{} () ->{io} Cap^ =
() => () => io // error
new Foo
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-custom-args/captures/outer-var.check
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
16 | var finalizeActions = collection.mutable.ListBuffer[() => Unit]() // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Found: scala.collection.mutable.ListBuffer[box () => Unit]
| Required: scala.collection.mutable.ListBuffer[box () ->? Unit]
| Required: scala.collection.mutable.ListBuffer[box () ->? Unit]^?
|
| Note that the universal capability `cap`
| cannot be included in capture set ? of variable finalizeActions
Expand Down

0 comments on commit 8d7a901

Please sign in to comment.