Skip to content

Commit ba08501

Browse files
committed
Fixing #22005
1 parent c933560 commit ba08501

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ trait CaptureRef extends TypeProxy, ValueType:
101101
* TODO: Document path cases
102102
*/
103103
final def subsumes(y: CaptureRef)(using Context): Boolean =
104-
104+
105105
def subsumingRefs(x: Type, y: Type): Boolean = x match
106106
case x: CaptureRef => y match
107107
case y: CaptureRef => x.subsumes(y)
@@ -135,13 +135,21 @@ trait CaptureRef extends TypeProxy, ValueType:
135135
case _ => false
136136
|| viaInfo(y.info)(subsumingRefs(this, _))
137137
case MaybeCapability(y1) => this.stripMaybe.subsumes(y1)
138+
case y: TypeRef if y.symbol.info.derivesFrom(defn.Caps_CapSet) =>
139+
y.info match
140+
case _: TypeAlias => y.captureSetOfInfo.elems.exists(this.subsumes)
141+
case TypeBounds(_, hi: CaptureRef) => this.subsumes(hi)
142+
case _ => false
138143
case _ => false
139144
|| this.match
140145
case ReachCapability(x1) => x1.subsumes(y.stripReach)
141146
case x: TermRef => viaInfo(x.info)(subsumingRefs(_, y))
142147
case x: TermParamRef => subsumesExistentially(x, y)
143148
case x: TypeRef if x.symbol.info.derivesFrom(defn.Caps_CapSet) =>
144-
x.captureSetOfInfo.elems.exists(_.subsumes(y))
149+
x.info match
150+
case _: TypeAlias => x.captureSetOfInfo.elems.exists(_.subsumes(y))
151+
case TypeBounds(lo: CaptureRef, _) => lo.subsumes(y)
152+
case _ => false
145153
case x: TypeRef => assumedContainsOf(x).contains(y)
146154
case _ => false
147155
end subsumes

tests/neg-custom-args/captures/capture-poly.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import caps.*
33
trait Foo extends Capability
44

55
trait CaptureSet:
6-
type C <: CapSet^
6+
type C^
77

88
def capturePoly[C^](a: Foo^{C^}): Foo^{C^} = a
99
def capturePoly2(c: CaptureSet)(a: Foo^{c.C^}): Foo^{c.C^} = a
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import caps.*
2+
3+
class IO
4+
class File(io: IO^)
5+
6+
class Handler[C^]:
7+
def f(file: File^): File^{C^} = file // error
8+
def g(file: File^{C^}): File^ = file // ok

0 commit comments

Comments
 (0)