Skip to content

Commit 5fc498a

Browse files
committed
Recognize double annotated capabilities such as x*?
x*? is x.type @reach @maybe. This was not recognized before.
1 parent fa85416 commit 5fc498a

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureOps.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,8 @@ object CapsOfApply:
639639
class AnnotatedCapability(annot: Context ?=> ClassSymbol):
640640
def apply(tp: Type)(using Context) =
641641
AnnotatedType(tp, Annotation(annot, util.Spans.NoSpan))
642-
def unapply(tree: AnnotatedType)(using Context): Option[SingletonCaptureRef] = tree match
643-
case AnnotatedType(parent: SingletonCaptureRef, ann) if ann.symbol == annot => Some(parent)
642+
def unapply(tree: AnnotatedType)(using Context): Option[CaptureRef] = tree match
643+
case AnnotatedType(parent: CaptureRef, ann) if ann.symbol == annot => Some(parent)
644644
case _ => None
645645

646646
/** An extractor for `ref @annotation.internal.reachCapability`, which is used to express
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import language.experimental.captureChecking
2+
import caps.Capability
3+
4+
trait File extends Capability
5+
6+
class Resource[T <: Capability](gen: T):
7+
def use[U](f: T => U): U =
8+
f(gen) // error
9+
10+
@main def run =
11+
val myFile: File = ???
12+
val r = Resource(myFile) // error
13+
()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class C
2+
def test(x: C^, y: C^) =
3+
class D {
4+
println(x)
5+
def foo() = println(y)
6+
}
7+
val d = D()
8+
val _: D^{y} = d // error, should be ok
9+
val _: D = d // error
10+
11+
val f = () => println(D())
12+
val _: () ->{x} Unit = f // ok
13+
val _: () -> Unit = f // should be error
14+
15+
def g = () =>
16+
println(x)
17+
() => println(y)
18+
val _: () ->{x} () ->{y} Unit = g // error, should be ok
19+
val _: () -> () -> Unit = g // error
20+

0 commit comments

Comments
 (0)