Closed
Description
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