Fixes for capture checking case class methods - #25278
Merged
Merged
Conversation
Needed so that we can call it from Setup as well.
These fell through the cracks before. There's still a hole: External global objects don't get their capture set implied by fields. So if they do not extend a Capability trait they are deemed pure, even if they contain capability fields. See console-use in pending tests. There are two ways to fix this: - Also do capturesImpliedByFields for global objects so that their capset is computed structurally. - Or, require that global objects with capability fields extend the appropriate capability class.
Contributor
|
Is this ready-for-review? |
Contributor
Author
|
Yes, ready for review |
Contributor
Author
|
@Linyxus ping for review |
Linyxus
approved these changes
Feb 25, 2026
odersky
added a commit
that referenced
this pull request
Mar 24, 2026
If a class extends a Capability, it will now get a LocalCap on creation. This solves the problem that ```scala class C extends Capability val a = C() val b: C = C() ``` did two different things: `a` was pure but `b` was impure. Now they are both impure. Based on #25278 Also, several other new rules around capture sets of `new`, outlined on the doc page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #23823.
We special treat primary constructors when we compute the result capture set. We need to do the same for case class
applyandcopymethods.The result type is patched when we instantiate one of these methods with arguments. I tried to do that as a transform of the info of these methods instead. That almost worked, but failed because of the unbox operation needed in
refineConctructorInstancewhich needs to know the actual arguments. This is a tricky bit. I added some comments torefineConctructorInstance.As part of this amandoned attempt to work on info transformers in Setup, I moved a lot of machinery needed by
refineConctructorInstancefromCheckCapturesintoCaptureOps. It's not strictly necessary to do that since in the final PR the only root call is fromCheckCaptures. But it might be needed later, so kept the refactoring.