Skip to content

Conversation

Linyxus
Copy link
Contributor

@Linyxus Linyxus commented May 18, 2023

This improves the completeness of capture checking in the following case:

def run(io: IO^)(op: Op^{io}): Unit = ???
val myIO: IO^ = ???
val myOp: Op^{myIO} = ???
run(myIO)(myOp)

The last line previously won't work because when substitute the parameter io to myIO in the type (op: Op^{io}): Unit the type Op^{io} get approximated into Nothing contravariantly. This is an overshot since the substitution [io := myIO] is exact (or precise) and the approximation (or avoidance) is unnecessary.

This commit resolves this issue by checking whether the to only contains CaptureRef in SubstParamsMap. If this condition is met, then it is an exact substitution and we can apply it on the capture set without approximations.

This improves the completeness of capture checking in the following case:
```scala
def run(io: IO^)(op: Op^{io}): Unit = ???
val myIO: IO^ = ???
val myOp: Op^{myIO} = ???
run(myIO)(myOp)
```
The last line previously won't work because when substitute the parameter `io`
to `myIO` in the type `(op: Op^{io}): Unit` the type `Op^{io}` get approximated
into `Nothing` contravariantly. This is an overshot since the substitution [io
:= myIO] is exact (or precise) and the approximation (or avoidance) is
unnecessary.

This commit resolves this issue by checking whether the `to` only contains
`CaptureRef` in `SubstParamsMap`. If this condition is met, then it is an exact
substitution and we can apply it on the capture set without approximations.
@Linyxus Linyxus requested a review from odersky May 19, 2023 12:02
@Linyxus Linyxus merged commit fe08f5f into scala:main May 22, 2023
@Linyxus Linyxus deleted the cc-param-subst-exact branch May 22, 2023 16:41
@Kordyjan Kordyjan added this to the 3.3.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants