From 001901d9544c29e3ee09323fe911cd6131e1e17f Mon Sep 17 00:00:00 2001 From: Yichen Xu Date: Wed, 1 Jan 2025 16:59:23 +0000 Subject: [PATCH 1/2] Capture stripping for capture variables Given a capture set variable `C`, its `stripCapturing` should be just `CapSet`. --- compiler/src/dotty/tools/dotc/cc/CaptureOps.scala | 2 ++ 1 file changed, 2 insertions(+) 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 From 32e550b0a4515f6f477146b3653f6ac84eb9dca4 Mon Sep 17 00:00:00 2001 From: Yichen Xu Date: Wed, 1 Jan 2025 17:01:32 +0000 Subject: [PATCH 2/2] Add test cases for #22103 --- tests/pos-custom-args/captures/i22103-alt.scala | 8 ++++++++ tests/pos-custom-args/captures/i22103.scala | 15 +++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/pos-custom-args/captures/i22103-alt.scala create mode 100644 tests/pos-custom-args/captures/i22103.scala 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