-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #21868, #21869, and #21870: handle CapsOf in more places #21875
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import caps.* | ||
|
||
class IO | ||
|
||
case class File(io: IO^) | ||
|
||
def test(io1: IO^, io2: IO^) = | ||
def f[C >: CapSet^{io1} <: CapSet^](file: File^{C^}) = ??? | ||
val f1: File^{io1} = ??? | ||
val f2: File^{io2} = ??? | ||
val f3: File^{io1, io2} = ??? | ||
f[CapSet^{io1}](f1) | ||
f[CapSet^{io1}](f2) // error | ||
f[CapSet^{io1}](f3) // error | ||
f[CapSet^{io2}](f2) // error | ||
f[CapSet^{io1, io2}](f1) | ||
f[CapSet^{io1, io2}](f2) | ||
f[CapSet^{io1, io2}](f3) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import caps.* | ||
|
||
trait Foo extends Capability | ||
|
||
trait CaptureSet: | ||
type C <: CapSet^ | ||
|
||
def capturePoly[C^](a: Foo^{C^}): Foo^{C^} = a | ||
def capturePoly2(c: CaptureSet)(a: Foo^{c.C^}): Foo^{c.C^} = a | ||
|
||
def test = | ||
val x: Foo^ = ??? | ||
val y: Foo^ = ??? | ||
|
||
object X extends CaptureSet: | ||
type C = CapSet^{x} | ||
|
||
val z1: Foo^{X.C^} = x | ||
val z2: Foo^{X.C^} = y // error | ||
|
||
val z3: Foo^{x} = capturePoly(x) | ||
val z4: Foo^{x} = capturePoly(y) // error | ||
|
||
val z5: Foo^{x} = capturePoly2(X)(x) | ||
val z6: Foo^{x} = capturePoly2(X)(y) // error |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import caps.* | ||
|
||
trait AbstractWrong: | ||
type C <: CapSet | ||
def boom(): Unit^{C^} // error | ||
|
||
trait Abstract: | ||
type C <: CapSet^ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idealy, we'd like to retrict the capture parameter and member bounded by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's certainly cleaner. The question is how far we want to take it for now. A fully general solution would also have to deal with the presence of explicit lower bounds, which could be themselves type variables, etc. trait Abstract[L >: CapSet^{}]:
type T >: L <: CapSet^ Maybe let's track this in a separate issue? The point of the current fix is to prevent the uncaught exception and compiler crash. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is an issue, as long as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the below examples show, there's a still a few quirks. I'm also somewhat uneasy with automatically presuming that the lower bound of a Since the specific issues are resolved, let's merge this and have a separate issue to make capture set intervals and subtyping airtight. |
||
def boom(): Unit^{C^} | ||
|
||
class Concrete extends Abstract: | ||
type C = Nothing | ||
def boom() = () // error | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@odersky Do you remember why we require the arguments of
CapsOf
to be abstract before? I think any type derived from CapSet should work.