Skip to content

Commit 1452ba2

Browse files
authored
Expand Capability types also in arguments of Capability classes (#23427)
Fixes #23422
2 parents a8f2e1f + ec6e604 commit 1452ba2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,14 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
403403
*/
404404
def defaultApply(t: Type) =
405405
if t.derivesFromCapability
406+
&& t.typeParams.isEmpty
406407
&& !t.isSingleton
407408
&& (!sym.isConstructor || (t ne tp.finalResultType))
408409
// Don't add ^ to result types of class constructors deriving from Capability
409-
then CapturingType(t, CaptureSet.CSImpliedByCapability(), boxed = false)
410+
then
411+
normalizeCaptures(mapOver(t)) match
412+
case t1 @ CapturingType(_, _) => t1
413+
case t1 => CapturingType(t1, CaptureSet.CSImpliedByCapability(), boxed = false)
410414
else normalizeCaptures(mapFollowingAliases(t))
411415

412416
def innerApply(t: Type) =
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import language.experimental.captureChecking
2+
import caps.*
3+
trait Cap
4+
class Inv[T] extends Capability
5+
class Inv2[T]
6+
class Inv3[T] extends Mutable
7+
def test(c: Cap^): Unit =
8+
val t1: Inv[() ->{c} Unit] = Inv() // error
9+
val t2: Inv2[() ->{c} Unit] = Inv2() // ok
10+
val t3: Inv3[() ->{c} Unit] = Inv3() // error, too

0 commit comments

Comments
 (0)