Skip to content

Commit

Permalink
Fixing #22005
Browse files Browse the repository at this point in the history
  • Loading branch information
noti0na1 committed Nov 22, 2024
1 parent c933560 commit ba08501
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
12 changes: 10 additions & 2 deletions compiler/src/dotty/tools/dotc/cc/CaptureRef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ trait CaptureRef extends TypeProxy, ValueType:
* TODO: Document path cases
*/
final def subsumes(y: CaptureRef)(using Context): Boolean =

def subsumingRefs(x: Type, y: Type): Boolean = x match
case x: CaptureRef => y match
case y: CaptureRef => x.subsumes(y)
Expand Down Expand Up @@ -135,13 +135,21 @@ trait CaptureRef extends TypeProxy, ValueType:
case _ => false
|| viaInfo(y.info)(subsumingRefs(this, _))
case MaybeCapability(y1) => this.stripMaybe.subsumes(y1)
case y: TypeRef if y.symbol.info.derivesFrom(defn.Caps_CapSet) =>
y.info match
case _: TypeAlias => y.captureSetOfInfo.elems.exists(this.subsumes)
case TypeBounds(_, hi: CaptureRef) => this.subsumes(hi)
case _ => false
case _ => false
|| this.match
case ReachCapability(x1) => x1.subsumes(y.stripReach)
case x: TermRef => viaInfo(x.info)(subsumingRefs(_, y))
case x: TermParamRef => subsumesExistentially(x, y)
case x: TypeRef if x.symbol.info.derivesFrom(defn.Caps_CapSet) =>
x.captureSetOfInfo.elems.exists(_.subsumes(y))
x.info match
case _: TypeAlias => x.captureSetOfInfo.elems.exists(_.subsumes(y))
case TypeBounds(lo: CaptureRef, _) => lo.subsumes(y)
case _ => false
case x: TypeRef => assumedContainsOf(x).contains(y)
case _ => false
end subsumes
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-custom-args/captures/capture-poly.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import caps.*
trait Foo extends Capability

trait CaptureSet:
type C <: CapSet^
type C^

def capturePoly[C^](a: Foo^{C^}): Foo^{C^} = a
def capturePoly2(c: CaptureSet)(a: Foo^{c.C^}): Foo^{c.C^} = a
Expand Down
8 changes: 8 additions & 0 deletions tests/neg-custom-args/captures/i22005.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import caps.*

class IO
class File(io: IO^)

class Handler[C^]:
def f(file: File^): File^{C^} = file // error
def g(file: File^{C^}): File^ = file // ok

0 comments on commit ba08501

Please sign in to comment.