Skip to content

Capture checking and SAM #24901

@nrinaudo

Description

@nrinaudo

Compiler version

3.8.0-RC3 and 3.8.1-RC1-bin-20260105-f08de70-NIGHTLY

Minimized code

//> using scala 3.nightly
//> using option -language:experimental.captureChecking

import caps.*

trait Rand extends SharedCapability

trait Plan:
  def execute(test: Rand ?=> Unit): Boolean

object Plan:
  def execute(test: Rand ?=> Unit): Boolean =
    true

  val standard: Plan =
    test =>
      execute(test)

Output

[error] Capability cap outlives its scope: it leaks into outer capture set 's1 of parameter test.
[error] The leakage occurred when trying to match the following types:
[error] 
[error] Found:    (contextual$1: rep$_.this.Rand^'s2) ?->{test} Unit
[error] Required: (rep$_.this.Rand^) ?=> Unit
[error] 
[error] where:    ?=> refers to a fresh root capability created in anonymous function of type (test²: (rep$_.this.Rand) ?=> Unit): Boolean when checking argument to parameter test of method execute
[error]           ^   refers to the universal root capability
[error]           cap is a fresh root capability classified as SharedCapability created in anonymous function of type (using contextual$1: rep$_.this.Rand^'s2): Unit of parameter parameter contextual$1² of method $anonfun
[error]       execute(test)

Expectation

I was (perhaps naively) expecting this to compile.

Context

More context can be found in the original scala users discussion.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions