-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Sema: Diagnose availability of storage accessors in key paths and writebacks #72410
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
Sema: Diagnose availability of storage accessors in key paths and writebacks #72410
Conversation
ef1e892
to
3e5bee4
Compare
3e5bee4
to
902721a
Compare
@swift-ci please test |
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.
LGTM! I think we might want to consider staging this error as a warning?
Thanks! I'd like to see how it goes with an error but I'm prepared to downgrade if necessary. |
@swift-ci please test source compatibility |
Let's see if any of our source compatibility suite projects have this problem. |
I checked the results and there are no regressions (there are some known issues from non-copyable generics adoption). |
Great, thank you! |
Fixes the missing diagnostic about the availability of the setter of `x` in the following example: ``` struct S { var x: Int { get { 0 } @available(*, unavailable) set {} } } var s = S() s[keyPath: \.x] = 1 ``` Resolves rdar://124977727
In the following example, the writeback via the property `b` should be diagnosed since `b`'s setter is unavailable: ``` struct A { struct B { var x: Int = 0 } private var _b: B = B() var b: B { get { _b } @available(*, unavailable) set { _b = newValue } } } var a = A() a.b.x = 1 ``` Resolves rdar://125019717
902721a
to
c7f0c58
Compare
@swift-ci please smoke test |
@swift-ci please smoke test Windows |
The changes in swiftlang#72410 caused a regression when checking availability in the following example: ``` // warning: Setter for 'hasDeprecatedSetter' is deprecated: ... x[y.hasDeprecatedSetter] = ... ``` The result of `y.hasDeprecatedSetter` is being passed as an argument to the subscript and its setter will not be called. To fix this, `ExprAvailabilityWalker` now consistently creates a new default `MemberAccessContext` when descending into any `Argument`, since the access context for the expressions surrounding the call should not affect the arguments to the call. Additionally, `MemberAccessContext` has been refactored to better model context state transitions. Instead of only modeling which accessors will be called, the enumeration's members now reflect the possible states that `ExprAvailabilityWalker` can be in during its traversal. This should hopefully make it easier to follow the logic for traversal of `LoadExpr`s and arguments. Resolves rdar://130487998.
The changes in swiftlang#72410 caused a regression when checking availability in the following example: ``` // warning: Setter for 'hasDeprecatedSetter' is deprecated: ... x[y.hasDeprecatedSetter] = ... ``` The result of `y.hasDeprecatedSetter` is being passed as an argument to the subscript and its setter will not be called. To fix this, `ExprAvailabilityWalker` now consistently creates a new default `MemberAccessContext` when descending into any `Argument`, since the access context for the expressions surrounding the call should not affect the arguments to the call. Additionally, `MemberAccessContext` has been refactored to better model context state transitions. Instead of only modeling which accessors will be called, the enumeration's members now reflect the possible states that `ExprAvailabilityWalker` can be in during its traversal. This should hopefully make it easier to follow the logic for traversal of `LoadExpr`s and arguments. Resolves rdar://130487998.
The changes in swiftlang#72410 caused a regression when checking availability in the following example: ``` // warning: Setter for 'hasDeprecatedSetter' is deprecated: ... x[y.hasDeprecatedSetter] = ... ``` The result of `y.hasDeprecatedSetter` is being passed as an argument to the subscript and its setter will not be called. To fix this, `ExprAvailabilityWalker` now consistently creates a new default `MemberAccessContext` when descending into any `Argument`, since the access context for the expressions surrounding the call should not affect the arguments to the call. Additionally, `MemberAccessContext` has been refactored to better model context state transitions. Instead of only modeling which accessors will be called, the enumeration's members now reflect the possible states that `ExprAvailabilityWalker` can be in during its traversal. This should hopefully make it easier to follow the logic for traversal of `LoadExpr`s and arguments. Resolves rdar://130487998.
Builds on #72369.
Fixes the missing diagnostics about the availability of property accessors in the following examples:
Resolves rdar://124977727 and rdar://125019717