Skip to content

Commit f4c09e3

Browse files
committed
Fix toFunctionType for methods containing reach capabilities in the result type
1 parent 496c866 commit f4c09e3

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ import config.Printers.{core, typr, matchTypes}
3838
import reporting.{trace, Message}
3939
import java.lang.ref.WeakReference
4040
import compiletime.uninitialized
41-
import cc.{CapturingType, CaptureRef, CaptureSet, SingletonCaptureRef, isTrackableRef,
42-
derivedCapturingType, isBoxedCapturing, isCaptureChecking, isRetains, isRetainsLike}
41+
import cc.*
4342
import CaptureSet.{CompareResult, IdempotentCaptRefMap, IdentityCaptRefMap}
4443

4544
import scala.annotation.internal.sharable
@@ -4070,6 +4069,10 @@ object Types extends TypeUtils {
40704069
range(defn.NothingType, atVariance(1)(apply(tp.underlying)))
40714070
case CapturingType(_, _) =>
40724071
mapOver(tp)
4072+
case ReachCapability(tp1) =>
4073+
apply(tp1) match
4074+
case tp1a: CaptureRef if tp1a.isTrackableRef => tp1a.reach
4075+
case _ => defn.captureRoot.termRef
40734076
case AnnotatedType(parent, ann) if ann.refersToParamOf(thisLambdaType) =>
40744077
val parent1 = mapOver(parent)
40754078
if ann.symbol.isRetainsLike then
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/depfun-reach.scala:13:4 ----------------------------------
2+
13 | op // error
3+
| ^^
4+
| Found: (xs: List[(X, box () ->{io} Unit)]) ->{op} List[box () ->{xs*} Unit]
5+
| Required: (xs: List[(X, box () ->{io} Unit)]) => List[() -> Unit]
6+
|
7+
| longer explanation available when compiling with `-explain`
8+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/depfun-reach.scala:20:60 ---------------------------------
9+
20 | val b: (xs: List[() ->{io} Unit]) => List[() ->{} Unit] = a // error
10+
| ^
11+
| Found: (xs: List[box () ->{io} Unit]) ->{a} List[box () ->{xs*} Unit]
12+
| Required: (xs: List[box () ->{io} Unit]) => List[() -> Unit]
13+
|
14+
| longer explanation available when compiling with `-explain`
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import language.experimental.captureChecking
2+
import caps.cap
3+
4+
def test(io: Object^, async: Object^) =
5+
def compose(op: List[(() ->{cap} Unit, () ->{cap} Unit)]): List[() ->{op*} Unit] =
6+
List(() => op.foreach((f,g) => { f(); g() }))
7+
8+
def compose1(op: List[(() ->{async} Unit, () ->{io} Unit)]): List[() ->{op*} Unit] =
9+
compose(op)
10+
11+
def foo[X](op: (xs: List[(X, () ->{io} Unit)]) => List[() ->{xs*} Unit])
12+
: (xs: List[(X, () ->{io} Unit)]) => List[() ->{} Unit] =
13+
op // error
14+
15+
def boom(op: List[(() ->{async} Unit, () ->{io} Unit)]): List[() ->{} Unit] =
16+
foo(compose1)(op)
17+
18+
def test2(io: Object^) =
19+
val a: (xs: List[() ->{io} Unit]) => List[() ->{xs*} Unit] = ???
20+
val b: (xs: List[() ->{io} Unit]) => List[() ->{} Unit] = a // error

tests/pos-custom-args/captures/gears-problem.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ extension [T](@use fs: Seq[Future[T]^])
1616
val collector: Collector[T]{val futures: Seq[Future[T]^{fs*}]}
1717
= Collector(fs)
1818
// val ch = collector.results // also errors
19-
val fut: Future[T]^{fs*} = collector.results.read().right.get // found ...^{caps.cap}
19+
val fut: Future[T]^{fs*} = collector.results.read().right.get // found ...^{caps.cap}
20+
21+
val ch = collector.results
22+
val item = ch.read()
23+
val r = item.right
24+
val fut2: Future[T]^{fs*} = r.get

0 commit comments

Comments
 (0)