-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix warning: overlapping access to 'self' #1337
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
Conversation
> Overlapping accesses to 'self', but modification requires exclusive access; consider copying to a local variable
Foundation/NSCalendar.swift
Outdated
@@ -583,8 +583,9 @@ open class NSCalendar : NSObject, NSCopying, NSSecureCoding { | |||
var at: CFAbsoluteTime = date.timeIntervalSinceReferenceDate | |||
|
|||
let res: Bool = withUnsafeMutablePointer(to: &at) { t in | |||
let copy = vector | |||
return vector.withUnsafeMutableBufferPointer { (vectorBuffer: inout UnsafeMutableBufferPointer<Int32>) in |
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.
Would let count = Int32(vector.count)
be better to reduce the size of the copy?
TestFoundation/TestNSData.swift
Outdated
mutatingHello.withUnsafeMutableBytes { (bytes : UnsafeMutablePointer<UInt8>) in | ||
XCTAssertEqual(bytes.pointee, 0x68, "First byte should be 0x68") | ||
|
||
// Mutate it | ||
bytes.pointee = 0x67 | ||
XCTAssertEqual(bytes.pointee, 0x67, "First byte should be 0x67") | ||
XCTAssertEqual(mutatingHello[0], 0x67, "First byte accessed via other method should still be 0x67") | ||
XCTAssertEqual(copy[0], 0x67, "First byte accessed via other method should still be 0x67") | ||
|
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.
Isn't this copy making the test redundant?
Would moving the XCTAssertEqual(mutatingHello[0] ...
outside of the closure give the same effect?
@swift-ci please test |
Those fixes look good. |
@swift-ci please test and merge |
Fix an exclusivity warning in TestNSData by moving assertions outside outside of a withUnsafeMutableByte() closure. This mirrors the approach taken by swiftlang#1337 to avoid the analogous warning in a similar test in this file.
There are more of these in the codebase, but here's a fix for a few.