-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Borrowing Accessors #3061
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
Borrowing Accessors #3061
Conversation
| } | ||
| ``` | ||
|
|
||
| We believe the above problem is unlikely to arise in practice. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swift Collections fails to compile (Swift 6.2.3, Xcode 26.2) when the yielding CoroutineAccessors experimental feature (SE-0474) is enabled.
Error: anonymous closure argument not contained in a closure
Swift Collections also has borrow() and mutate() methods, but they don't take trailing closures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The final SE-0474 switched to yielding borrow and yielding mutate. The PR to implement the new terms is swiftlang/swift#86277. So the issue you describe here should be resolved by that.
We started to experiment with parser-level approaches to disambiguate such cases while working on the implementation of SE-0474 but then instead changed the keywords to avoid it. We may need to revisit those ideas for these borrowing accessors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CC: @meg-gupta
Following the [Prospective Vision] Accessors
we're now ready to formally propose
borrowandmutateaccessors which allow a property or subscript to return a borrowed value with full exclusivity safety checks.