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

Closed
natsukagami opened this issue May 15, 2025 · 1 comment
Closed
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

odersky added a commit to dotty-staging/dotty that referenced this issue May 19, 2025
Fixes scala#23170

This was disabled before. We also had to slightly extend fresh/cap collapsing
to make override checks go through under the new scheme.
odersky added a commit to dotty-staging/dotty that referenced this issue May 21, 2025
Fixes scala#23170

This was disabled before. We also had to slightly extend fresh/cap collapsing
to make override checks go through under the new scheme.
EnzeXing pushed a commit to EnzeXing/dotty that referenced this issue May 27, 2025
Fixes scala#23170

This was disabled before. We also had to slightly extend fresh/cap collapsing
to make override checks go through under the new scheme.
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

Successfully merging a pull request may close this issue.

2 participants