-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[WIP] Property behaviors #23292
Closed
Closed
[WIP] Property behaviors #23292
Conversation
This file contains 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
…ble. When a variable has a property behavior, wrap the type of the variable in the property behavior type. For example, a property behavior “Lazy” should be written as Lazy<T>. A variable declared as var someLazyInt: Int by Lazy will have a storage type of Lazy<Int>.
When a property behavior contains an initializer init(initialValue:), the initial value provided to a variable using that property behavior will be implicitly passes to the behavior’s init(initialValue:) initializer. This allows property behavior types to opt-in to being initialized implicitly, from a value of their stored type.
When referencing a property that has a property behavior, implicitly reference the `value` of the behavior to see the underlying type of the property.
Implement a very tightly-bound ^ prefix operator to access the behavior of a property that has a behavior, suppressing the implicit “unwrap” that looks at the underlying value.
If a property behavior’s “value” itself has a property behavior, also implicitly unwrap that and allow suppression of any number of levels of that implicit unwrapping with, e.g., ^(^doubleWrapped).
…rap. The ^ binds tightly to an identifier or parenthesized expression, so after forming the suppress-unwrap expression, parse a postfix expression suffix (if any).
@swift-ci please test source compatibility |
@swift-ci please test source compatibility release |
I'm abandoning this approach in favor of #23440 |
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.
A different, experimental take on property behaviors.