diff --git a/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala b/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala index bc4eb92234eb..a6c45fcac20d 100644 --- a/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala +++ b/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala @@ -359,6 +359,8 @@ extension (tp: Type) parent.stripCapturing case atd @ AnnotatedType(parent, annot) => atd.derivedAnnotatedType(parent.stripCapturing, annot) + case tp if tp.derivesFrom(defn.Caps_CapSet) => + defn.Caps_CapSet.typeRef case _ => tp diff --git a/tests/pos-custom-args/captures/i22103-alt.scala b/tests/pos-custom-args/captures/i22103-alt.scala new file mode 100644 index 000000000000..c08c6b5a4e4d --- /dev/null +++ b/tests/pos-custom-args/captures/i22103-alt.scala @@ -0,0 +1,8 @@ +import language.experimental.captureChecking +import caps.* + +trait F[+Cap^] +def expect[C^](x: F[C]): x.type = x + +def test[C^](x: F[C], io: () => Unit): Unit = + val t1 = expect[CapSet^{C^}](x) diff --git a/tests/pos-custom-args/captures/i22103.scala b/tests/pos-custom-args/captures/i22103.scala new file mode 100644 index 000000000000..a3c7bfe57251 --- /dev/null +++ b/tests/pos-custom-args/captures/i22103.scala @@ -0,0 +1,15 @@ +import language.experimental.captureChecking +import caps.* + +abstract class Source[+T, Cap^]: + def transformValuesWith[U](f: (T -> U)^{Cap^}): Source[U, Cap]^{this, f} = ??? + +def race[T, Cap^](sources: Source[T, Cap]^{Cap^}*): Source[T, Cap]^{Cap^} = ??? + +def either[T1, T2, Cap^]( + //io: () => Unit, + src1: Source[T1, Cap]^{Cap^}, + src2: Source[T2, Cap]^{Cap^}): Source[Either[T1, T2], Cap]^{Cap^} = + val left = src1.transformValuesWith(Left(_)) + val right = src2.transformValuesWith(Right(_)) + race[Either[T1, T2], CapSet^{Cap^}](left, right) // <- rejected