Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Test to show that exceptions can't leak capabilities
  • Loading branch information
odersky committed Feb 19, 2026
commit 2bd9092fd54ca333ee0ede32a0c0871c6522d421
8 changes: 8 additions & 0 deletions tests/neg-custom-args/captures/exception-leak.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Error: tests/neg-custom-args/captures/exception-leak.scala:4:8 ------------------------------------------------------
4 | self: E^ => // error
| ^^
| E is a pure type, it makes no sense to add a capture set to it
-- [E223] CaptureChecking Error: tests/neg-custom-args/captures/exception-leak.scala:1:8 -------------------------------
1 |class E(f: () => Unit) extends Exception // error
| ^
| Reference `E.this.f` is not included in the allowed capture set {} of the self type of class E.
10 changes: 10 additions & 0 deletions tests/neg-custom-args/captures/exception-leak.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class E(f: () => Unit) extends Exception // error

class E2(f: () => Unit) extends Exception:
self: E^ => // error

object Test extends caps.Mutable:
var x: Int = 0

update def foo() = throw E(() => x += 1)

Loading