Skip to content

Expressiveness problem with capture checking paths #22723

Open
@odersky

Description

@odersky

Compiler version

3.7.0RC1

Minimized example

import language.experimental.captureChecking
import caps.*

case class A()

trait HasCap:
  def mkA: A^{this}

object HasCap:
  def apply[T](body: HasCap^ ?=> T): T = ???

class Box(using h: HasCap^):
  var t: A^{h} = h.mkA

def main() =
  HasCap: h1 ?=>
    val b = Box(using h1)
    b.t = h1.mkA

Output

-- [E007] Type Mismatch Error: classcaps.scala:19:13 ---------------------------
19 |    b.t = h1.mkA
   |          ^^^^^^
   |          Found:    A^{h1}
   |          Required: A^{b.h}
   |
   | longer explanation available when compiling with `-explain`
[[syntax trees at end of                        cc]] // classcaps.scala

Expectation

It would be nice if there was no error. If we look at the generated code we find:

    def main(): Unit =
      HasCap.apply[Unit]((using h1: HasCap^) =>
        {
          val b: Box{val h: HasCap^{h1}}^{h1} = new Box(using h1)()
          b.t = h1.mkA
        }
      )

The problem here is that b.h <:< {h1} but we do not know that b.h == h1. We used to imply this, but it was unsound in general. /cc @noti0na1

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions