Skip to content

Leaking capability in Scott-encoded wrapper #15923

Open
@Linyxus

Description

@Linyxus

Compiler version

cc-experiment branch

Minimized code

trait Cap { def use(): Int }
type Id[X] = [T] -> (op: X => T) -> T
def mkId[X](x: X): Id[X] = [T] => (op: X => T) => op(x)

def bar() = {
  def withCap[X](op: ({*} Cap) => X): X = {
    val cap: {*} Cap = new Cap { def use() = { println("cap is used"); 0 } }
    val result = op(cap)
    result
  }

  val leak = withCap(cap => mkId(cap))
  leak { cap => cap.use() }   // bad
}

Output

It compiles.

Expectation

It should not compile. We expect the type of val leak to be Id[□ {*} Cap], so it will expect a function of (□ {*} Cap) => Unit in leak(...). It will not be possible to adapt cap => cap.use() : ({*} Cap) -> Unit to the type (□ {*} Cap) => Unit since the adaption cap => (unbox cap).use() tries to unbox a reference capturing universal capability.

We should issue an error on leak(...).

Metadata

Metadata

Assignees

Labels

cc-experimentIntended to be merged with cc-experiment branch on originitype:bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions