Skip to content
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

Implement correct capture check for lazy vals #21601

Open
odersky opened this issue Sep 17, 2024 · 0 comments
Open

Implement correct capture check for lazy vals #21601

odersky opened this issue Sep 17, 2024 · 0 comments
Assignees
Labels
area:experimental:cc Capture checking related cc-experiment Intended to be merged with cc-experiment branch on origin itype:bug

Comments

@odersky
Copy link
Contributor

odersky commented Sep 17, 2024

Compiler version

Minimized example

def f(c: T^, d: T^) = 
  lazy val x: T^{c} = d; c
  val f = () => x

Output

Compiling this with -Xprint:cc gives:

package <empty> {
  @SourceFile("tests/new/test.scala") class T() extends Object() {}
  final lazy module val test$package: test$package = new test$package()
  @SourceFile("tests/new/test.scala") final module class test$package() extends
    Object() {
    private[this] type $this = test$package.type
    private def writeReplace(): AnyRef =
      new scala.runtime.ModuleSerializationProxy(classOf[test$package.type])
    def f(c: T^, d: T^): Unit =
      {
        lazy val x: T^{c} =
          {
            d
            c
          }
        val f: () ->{x} (ex$1: caps.Exists) -> T^{x} =
          {
            def $anonfun(): T^{x} = x
            closure($anonfun)
          }
        ()
      }
  }
}

Expectation

f should also capture d, but this is not recorded.

Generally, we have spent no thought so far how to capture check lazy vals, and it looks interesting. Maybe someone wants to pick that up?

@odersky odersky added stat:needs triage Every issue needs to have an "area" and "itype" label cc-experiment Intended to be merged with cc-experiment branch on origin and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 17, 2024
@Gedochao Gedochao added area:experimental:cc Capture checking related itype:bug labels Sep 18, 2024
@bracevac bracevac self-assigned this Sep 19, 2024
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 cc-experiment Intended to be merged with cc-experiment branch on origin itype:bug
Projects
None yet
Development

No branches or pull requests

3 participants