You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refine rules for capture parameters and members (#22000)
This PR refines rules for capture set variables (parameters and
members).
Fix#21999, #22005, #22030
## Add requirements for capture set variables
When a capture set is encoded as a type, the type must refer to `CapSet`
and bounded by `>: CapSet <: CapSet^`.
An unbounded capture parameter would be `C >: CapSet <: CapSet^`, which
can be desugared from `C^`.
```scala
def f[C^](io: IO^{C^}) = ???
// becomes
def f[C >: CapSet <: CapSet^](io: IO^{C^}) = ???
```
We may consider the similar desugaring for type member in the future:
```scala
class A:
type C^
// becomes
class A:
type C >: CapSet <: CapSet^
```
Then, constaints between capture variables become possible:
```scala
def test[X^, Y^, Z >: X <: Y](x: C^{X^}, y: C^{Y^}, z: C^{Z^}) = ???
// Z is still bounded by >: CapSet <: CapSet^
```
Update definitions in the library `caps.scala`, such that a type
following the rule can be used inside a capture set.
```scala
// Rule out C^{(Nothing)^} during typer
def capsOf[CS >: CapSet <: CapSet @retainsCap]: Any = ???
sealed trait Contains[+C >: CapSet <: CapSet @retainsCap, R <: Singleton]
```
## Add cases to handle `CapSet` in `subsumes`
```
* X = CapSet^cx, exists rx in cx, rx subsumes y ==> X subsumes y
* Y = CapSet^cy, forall ry in cy, x subsumes ry ==> x subsumes Y
* X: CapSet^c1...CapSet^c2, (CapSet^c1) subsumes y ==> X subsumes y
* Y: CapSet^c1...CapSet^c2, x subsumes (CapSet^c2) ==> x subsumes Y
* Contains[X, y] ==> X subsumes y
```
## Fix some issues related to overriding
When deciding whether a class has a non-trivial self type, we look at
the underlying type without capture set.
[test_scala2_library_tasty]
0 commit comments