Skip to content

Avoid using Ranges in exact substitutions #17532

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

Merged
merged 1 commit into from
May 22, 2023

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