Skip to content

CC unsoundness: TypeComparer.glb strips capture set #18246

Closed
@Linyxus

Description

@Linyxus

Compiler version

main

Minimized code

import language.experimental.captureChecking
trait Cap
trait Foo[+T]

def magic[T](io: Cap^, x: Foo[T]^{io}): Foo[T]^{} =
  val x1: Foo[T]^{cap} & Foo[Any]^{io} = x
  val x2: Foo[T] = x1
  x2  // boom, an impure value becomes pure

Output

It compiles.

Expectation

It should be rejected.

Problematic glb trace:

==> glb(Foo[T]^, Foo[Any]^{io})?
  ==> glb(Foo[T], Foo[Any]^{io})?
    ==> glb(Foo[T], <notype>)?
    <== glb(Foo[T], <notype>) = Foo[T]
  <== glb(Foo[T], Foo[Any]^{io}) = Foo[T]
<== glb(Foo[T]^, Foo[Any]^{io}) = Foo[T]

Possible code location that causes this issue: https://github.com/lampepfl/dotty/blob/da16f434fa3aa74bcceacb04243f742a61f8b786/compiler/src/dotty/tools/dotc/core/TypeComparer.scala#L2603-L2609

Metadata

Metadata

Assignees

No one assigned

    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