-
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
Ignore capture sets in certain cases of subtyping #22183
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,47 @@ | ||
import language.experimental.captureChecking | ||
import caps.* | ||
|
||
def test[C^] = | ||
val a: C = ??? | ||
val b: CapSet^{C^} = a | ||
val c: C = b | ||
val d: CapSet^{C^, c} = a | ||
|
||
// TODO: make "CapSet-ness" of type variables somehow contagious? | ||
// Then we don't have to spell out the bounds explicitly... | ||
def testTrans[C^, D >: CapSet <: C, E >: CapSet <: D, F >: C <: CapSet^] = | ||
val d1: D = ??? | ||
val d2: CapSet^{D^} = d1 | ||
val d3: D = d2 | ||
val e1: E = ??? | ||
val e2: CapSet^{E^} = e1 | ||
val e3: E = e2 | ||
val d4: D = e1 | ||
val c1: C = d1 | ||
val c2: C = e1 | ||
val f1: F = c1 | ||
val d_e_f1: CapSet^{D^,E^,F^} = d1 | ||
val d_e_f2: CapSet^{D^,E^,F^} = e1 | ||
val d_e_f3: CapSet^{D^,E^,F^} = f1 | ||
val f2: F = d_e_f1 | ||
val c3: C = d_e_f1 // error | ||
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. This line and the three following lines are all not flagged as errors, but they should be. Investigating. |
||
val c4: C = f1 // error | ||
val e4: E = f1 // error | ||
val e5: E = d1 // error | ||
|
||
|
||
trait A[+T] | ||
|
||
trait B[-C] | ||
|
||
def testCong[C^, D^] = | ||
val a: A[C] = ??? | ||
val b: A[CapSet^{C^}] = a | ||
val c: A[CapSet^{D^}] = a // error | ||
val d: A[CapSet^{C^,D^}] = a | ||
val e: A[C] = d // error | ||
val f: B[C] = ??? | ||
val g: B[CapSet^{C^}] = f | ||
val h: B[C] = g | ||
val i: B[CapSet^{C^,D^}] = h // error | ||
val j: B[C] = i |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,4 @@ def either[T1, T2, Cap^]( | |
src2: Source[T2, Cap]^{Cap^}): Source[Either[T1, T2], Cap]^{Cap^} = | ||
val left = src1.transformValuesWith(Left(_)) | ||
val right = src2.transformValuesWith(Right(_)) | ||
race[Either[T1, T2], Cap](left, right) | ||
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. The extension methods above can be tested as well. I remember they have similar issues. 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. It causes an infinite regress now, looking into it. |
||
// Explicit type arguments are required here because the second argument | ||
// is inferred as `CapSet^{Cap^}` instead of `Cap`. | ||
// Although `CapSet^{Cap^}` subsumes `Cap` in terms of capture sets, | ||
// `Cap` is not a subtype of `CapSet^{Cap^}` in terms of subtyping. | ||
race(left, right) |
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.
We should support that. Say we have
def foo[C^, D <: C, E >: C]
, then we should automatically constraint bothD
andE
to be capture set variables, i.e.,D
is implicitly lower-bounded byCapSet
, andE
is implicitly upper-bounded byCapSet^