Skip to content

Suppress KVO warning when the property has an explicit setter #30098

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

Merged
merged 1 commit into from
Feb 27, 2020
Merged

Suppress KVO warning when the property has an explicit setter #30098

merged 1 commit into from
Feb 27, 2020

Conversation

theblixguy
Copy link
Collaborator

@theblixguy theblixguy commented Feb 27, 2020

In #28135, we added a new warning when a non-@objc dynamic property is passed to the KVO observe method, because passing such a property can lead to unexpected behaviour or runtime trap.

However, the user might have an @objc property (without the dynamic modifier) and perform the updates manually, by calling willChangeValue and didChangeValue:

private var _bar: Int = 0
@objc var bar: Int {
    get { _bar }
    set {
     guard newValue != _bar else { return }
     willChangeValue(for: \.bar)
     _bar = newValue
     didChangeValue(for: \.bar)
    }
  }

This is okay to do, so suppress the warning if we have an explicit setter on the @objc property. We could go further and check for those specific calls, but it's probably safe to assume that those calls are being made if there's an explicit setter.

Resolves SR-12286
Resolves rdar://problem/59702530
Resolves FB7595420

@theblixguy theblixguy requested a review from xedin February 27, 2020 19:07
@theblixguy
Copy link
Collaborator Author

@swift-ci please smoke test

1 similar comment
@xedin
Copy link
Contributor

xedin commented Feb 27, 2020

@swift-ci please smoke test

@theblixguy
Copy link
Collaborator Author

@xedin I'll create a new PR against swift-5.2 branch :)

@theblixguy
Copy link
Collaborator Author

Unrelated failure:

/home/buildnode/jenkins/workspace/swift-PR-Linux-smoke-test/branch-master/swiftpm/Tests/FunctionalTests/DependencyResolutionTests.swift:37: error: DependencyResolutionTests.testInternalComplex : failed - `swift build -c Release' failed:

@swift-ci please smoke test Linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants