Skip to content

@use is deprecated in capture checking, but in the case of capability polymorphism, it is still needed. #24087

@amsen20

Description

@amsen20

Overview

The following code can be compiled by adding @use before the capability type variable, but in recent versions, there is no way to get this code compiled because @use is deprecated.
There is also a test and a TODO related to this issue, but I don't know whether it is a bug and is going to be fixed or something else.

Compiler version

3.8.0-RC1-bin-20250814-0cf7a18-NIGHTLY

Minimized codes

The base code with capability polymorphism:

//> using scala 3.7.2
import language.experimental.captureChecking

def g[C^] = (xs: List[Object^{C}]) => xs.head

Compile error:

[error] Capture set parameter C leaks into capture scope of method g.
[error] To allow this, the type C should be declared with a @use annotation
[error] def g[C^] = (xs: List[Object^{C}]) => xs.head
[error]                                       ^^^^^^^

Modified version of the code that fixes the issue in 3.7.2:

//> using scala 3.7.2
import language.experimental.captureChecking
import caps.use

def g[@use C^] = (xs: List[Object^{C}]) => xs.head

The base code in 3.8.0-RC1-bin-20250814-0cf7a18-NIGHTLY

//> using scala 3.8.0-RC1-bin-20250814-0cf7a18-NIGHTLY
import language.experimental.captureChecking

def g[C^] = (xs: List[Object^{C}]) => xs.head

Compile error:

[error] Capture set parameter C leaks into capture scope of method g.
[error] def g[C^] = (xs: List[Object^{C}]) => xs.head
[error]                                       ^^^^^^^

The fixed version in 3.8.0-RC1-bin-20250814-0cf7a18-NIGHTLY:

//> using scala 3.8.0-RC1-bin-20250814-0cf7a18-NIGHTLY
import language.experimental.captureChecking
import caps.use

def g[@use C^] = (xs: List[Object^{C}]) => xs.head

Compile error:

[error] @use is redundant here and should no longer be written explicitly.
[error] Capset variables are always implicitly used, unless they are annotated with @caps.preserve.
[error] def g[@use C^] = (xs: List[Object^{C}]) => xs.head
[error]       ^^^^^^^

Expectation

There should be a way to modify the base code and compile it successfully in recent Scala versions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions