Skip to content

Conversation

@odersky
Copy link
Contributor

@odersky odersky commented Oct 28, 2025

x.rd is now a shorthand for x.only[caps.Read].

@odersky odersky added the area:experimental:cc Capture checking related label Oct 28, 2025
@natsukagami natsukagami self-requested a review October 30, 2025 14:26
@Linyxus
Copy link
Contributor

Linyxus commented Nov 4, 2025

It is surprising that this PR also fixes #24334.

@odersky
Copy link
Contributor Author

odersky commented Nov 5, 2025

@natsukagami ping for review

Copy link
Contributor

@natsukagami natsukagami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was slightly concerned with readonly not being a .only[Read] if we wanted to drop the cannot-capture-different-classifier restriction, but since we will take another route I think it's fine.

*/
object ReadOnly:
def apply(underlying: CoreCapability | RootCapability | Reach | Restricted)(using Context): Restricted =
Restricted(underlying.stripRestricted.asInstanceOf, defn.Caps_Read)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it valid here to strip the existing restricted? e.g. if the classifiers was extended with a sub-classifier of Read

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't support restrictions with more than one classifierr, so the only issue here is that we might want to keep the existing sub-classifier of Read (if such things exist). But I think that should be handled by the caller.

Copy link
Contributor

@Linyxus Linyxus Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we said Mutable should be a special "classifier" that allows its instance to capture anything. So we might well have a matrix m: Matrix^{fresh1, async} that captures a control capability Async (here the fresh1 is the Mutable fresh for this matrix). Then, getting readonly on m.only[Control].rd should, by principle, be empty. But with the current logic it will be m.rd or equivalently fresh1.rd.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a second thought I think it should be fine. This expressiveness issue could be solved by first widening m.only[Control] to just async and then take readonly on it.

Copy link
Contributor

@Linyxus Linyxus Nov 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a second thought I think it should be fine. This expressiveness issue could be solved by first widening m.only[Control] to just async and then take readonly on it, which will be empty.

@odersky odersky merged commit b1a5500 into scala:main Nov 5, 2025
53 checks passed
@odersky odersky deleted the readonly-classifier branch November 5, 2025 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:experimental:cc Capture checking related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Capture parameter on Mutable classes crashes the compiler

3 participants