Skip to content

Capture set parameters upper bounded by cap.rd cannot be widened to cap.rd #23170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
natsukagami opened this issue May 15, 2025 · 1 comment
Assignees
Labels
area:experimental:cc Capture checking related itype:bug

Comments

@natsukagami
Copy link
Contributor

Compiler version

Latest main (23469a1)

Minimized code

import language.experimental.captureChecking
import caps.*

trait A

extension (a: A^{cap.rd})
  def await = ()

def awaitA[C <: {cap.rd}](a: A^{C}) = a.await

Output

-- [E007] Type Mismatch Error: ../dotty-test/upcast-rd.scala:11:38 -------------
11 |def awaitA[C <: {cap.rd}](a: A^{C}) = a.await
   |                                      ^
   |Found:    (a : test.upcastrd.A^{C})
   |Required: test.upcastrd.A^{cap.rd}
   |
   |where:    cap is a fresh root capability created in method awaitA when checking argument to parameter a of method await
   |
   | longer explanation available when compiling with `-explain`

Expectation

Should compile.

@natsukagami
Copy link
Contributor Author

In the same vein, reach capabilities also don't work:

import language.experimental.captureChecking
import caps.*

trait Future[T]

extension [T](fut: Future[T]^{cap.rd})
  def await: T = ???

class Collector[T](val futs: Seq[Future[T]^{cap.rd}]):
  val results = Seq[Future[T]^{futs*}]()

extension [T](futs: Seq[Future[T]^{cap.rd}])
  def awaitAll =
    val collector = Collector(futs)
    collector.results.foreach((f: Future[T]^{futs*}) => f.await)
    futs.map(_.await)

gives

[error] ./fut.scala:17:57
[error] Found:    (f : test.fut.Future[T]^{futs*})
[error] Required: test.fut.Future[box T^?]^{cap.rd}
[error] 
[error] where:    cap is a fresh root capability created in anonymous function of type (f²: test.fut.Future[T]^{futs*}): T when checking argument to parameter fut of method await

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:experimental:cc Capture checking related itype:bug
Projects
None yet
Development

No branches or pull requests

2 participants