Skip to content

Commit 9d43c95

Browse files
committed
Suppress string interpolation warnings introduced by swift/6a48934:
- Avoid optional where no impact w/IUO - Else cast as Optional - Behavior change in Notification description() to avoid optional
1 parent d32f2e1 commit 9d43c95

File tree

8 files changed

+27
-25
lines changed

8 files changed

+27
-25
lines changed

Foundation/NSFileManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ open class FileManager : NSObject {
125125
for attribute in attributes.keys {
126126
if attribute == .posixPermissions {
127127
guard let number = attributes[attribute] as? NSNumber else {
128-
fatalError("Can't set file permissions to \(attributes[attribute])")
128+
fatalError("Can't set file permissions to \(attributes[attribute] as Any?)")
129129
}
130130
#if os(OSX) || os(iOS)
131131
let modeT = number.uint16Value

Foundation/NSKeyedArchiver.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ open class NSKeyedArchiver : NSCoder {
241241
}
242242

243243
private func _validateObjectSupportsSecureCoding(_ objv : Any?) {
244-
if objv != nil &&
245-
self.requiresSecureCoding &&
244+
if let objv = objv, self.requiresSecureCoding &&
246245
!NSKeyedArchiver._supportsSecureCoding(objv) {
247246
fatalError("Secure coding required when encoding \(objv)")
248247
}

Foundation/NSKeyedUnarchiver.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ open class NSKeyedUnarchiver : NSCoder {
418418

419419
if self.requiresSecureCoding && !supportsSecureCoding {
420420
// FIXME should this be a fatal error?
421-
fatalError("Archiver \(self) requires secure coding but class \(classToConstruct) does not support it")
421+
fatalError("Archiver \(self) requires secure coding but class \(classToConstruct as Optional) does not support it")
422422
}
423423

424424
return supportsSecureCoding
@@ -505,8 +505,7 @@ open class NSKeyedUnarchiver : NSCoder {
505505
*/
506506
private func _decodeObject(forKey key: String?) throws -> Any? {
507507
guard let objectRef : Any? = _objectInCurrentDecodingContext(forKey: key) else {
508-
throw _decodingError(CocoaError.coderValueNotFound,
509-
withDescription: "No value found for key \(key). The data may be corrupt.")
508+
throw _decodingError(CocoaError.coderValueNotFound, withDescription: "No value found for key \(key as Optional). The data may be corrupt.")
510509
}
511510

512511
return try _decodeObject(objectRef!)

Foundation/Notification.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ public struct Notification : ReferenceConvertible, Equatable, Hashable {
4040
public var hashValue: Int {
4141
return name.rawValue.hash
4242
}
43-
43+
4444
public var description: String {
45-
return "name = \(name.rawValue), object = \(object), userInfo = \(userInfo)"
45+
var description = "name = \(name.rawValue)"
46+
if let obj = object { description += ", object = \(obj)" }
47+
if let info = userInfo { description += ", userInfo = \(info)" }
48+
return description
4649
}
4750

4851
public var debugDescription: String {

TestFoundation/TestNSString.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ class TestNSString : XCTestCase {
872872
}
873873

874874
func test_stringByAppendingPathExtension() {
875-
let values : Dictionary = [
875+
let values = [
876876
NSString(string: "/tmp/scratch.old") : "/tmp/scratch.old.tiff",
877877
NSString(string: "/tmp/scratch.") : "/tmp/scratch..tiff",
878878
NSString(string: "/tmp/") : "/tmp.tiff",
@@ -882,7 +882,7 @@ class TestNSString : XCTestCase {
882882
]
883883
for (fileName, expectedResult) in values {
884884
let result = fileName.appendingPathExtension("tiff")
885-
XCTAssertEqual(result, expectedResult, "expected \(expectedResult) for \(fileName) but got \(result)")
885+
XCTAssertEqual(result, expectedResult, "expected \(expectedResult) for \(fileName) but got \(result as Optional)")
886886
}
887887
}
888888

TestFoundation/TestNSTimeZone.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class TestNSTimeZone: XCTestCase {
4747
let tz = NSTimeZone.system
4848
let abbreviation1 = tz.abbreviation()
4949
let abbreviation2 = tz.abbreviation(for: Date())
50-
XCTAssertEqual(abbreviation1, abbreviation2, "\(abbreviation1) should be equal to \(abbreviation2)")
50+
XCTAssertEqual(abbreviation1, abbreviation2, "\(abbreviation1 as Optional) should be equal to \(abbreviation2 as Optional)")
5151
}
5252

5353
func test_abbreviationDictionary() {
@@ -98,7 +98,7 @@ class TestNSTimeZone: XCTestCase {
9898

9999
let abbreviation1 = tz.abbreviation()
100100
let abbreviation2 = obj.abbreviation
101-
XCTAssertEqual(abbreviation1, abbreviation2, "\(abbreviation1) should be equal to \(abbreviation2)")
101+
XCTAssertEqual(abbreviation1, abbreviation2, "\(abbreviation1 as Optional) should be equal to \(abbreviation2 as Optional)")
102102

103103
let isDaylightSavingTime1 = tz.isDaylightSavingTime()
104104
let isDaylightSavingTime2 = obj.isDaylightSavingTime
@@ -112,7 +112,7 @@ class TestNSTimeZone: XCTestCase {
112112
let nextDaylightSavingTimeTransition1 = tz.nextDaylightSavingTimeTransition
113113
let nextDaylightSavingTimeTransition2 = obj.nextDaylightSavingTimeTransition
114114
let nextDaylightSavingTimeTransition3 = tz.nextDaylightSavingTimeTransition(after: Date())
115-
XCTAssert(nextDaylightSavingTimeTransition1 == nextDaylightSavingTimeTransition2 || nextDaylightSavingTimeTransition2 == nextDaylightSavingTimeTransition3, "\(nextDaylightSavingTimeTransition1) should be equal to \(nextDaylightSavingTimeTransition2), or in the rare circumstance where a daylight saving time transition has just occurred, \(nextDaylightSavingTimeTransition2) should be equal to \(nextDaylightSavingTimeTransition3)")
115+
XCTAssert(nextDaylightSavingTimeTransition1 == nextDaylightSavingTimeTransition2 || nextDaylightSavingTimeTransition2 == nextDaylightSavingTimeTransition3, "\(nextDaylightSavingTimeTransition1 as Optional) should be equal to \(nextDaylightSavingTimeTransition2 as Optional), or in the rare circumstance where a daylight saving time transition has just occurred, \(nextDaylightSavingTimeTransition2 as Optional) should be equal to \(nextDaylightSavingTimeTransition3 as Optional)")
116116
}
117117

118118
func test_knownTimeZoneNames() {
@@ -137,18 +137,18 @@ class TestNSTimeZone: XCTestCase {
137137
func test_initializingTimeZoneWithOffset() {
138138
let tz = TimeZone(identifier: "GMT-0400")
139139
XCTAssertNotNil(tz)
140-
let seconds = tz?.secondsFromGMT(for: Date())
140+
let seconds = tz?.secondsFromGMT(for: Date()) ?? 0
141141
XCTAssertEqual(seconds, -14400, "GMT-0400 should be -14400 seconds but got \(seconds) instead")
142142

143143
let tz2 = TimeZone(secondsFromGMT: -14400)
144144
XCTAssertNotNil(tz2)
145145
let expectedName = "GMT-0400"
146146
let actualName = tz2?.identifier
147-
XCTAssertEqual(actualName, expectedName, "expected name \"\(expectedName)\" is not equal to \"\(actualName)\"")
147+
XCTAssertEqual(actualName, expectedName, "expected name \"\(expectedName)\" is not equal to \"\(actualName as Optional)\"")
148148
let expectedLocalizedName = "GMT-04:00"
149149
let actualLocalizedName = tz2?.localizedName(for: .generic, locale: Locale(identifier: "en_US"))
150-
XCTAssertEqual(actualLocalizedName, expectedLocalizedName, "expected name \"\(expectedLocalizedName)\" is not equal to \"\(actualLocalizedName)\"")
151-
let seconds2 = tz2?.secondsFromGMT()
150+
XCTAssertEqual(actualLocalizedName, expectedLocalizedName, "expected name \"\(expectedLocalizedName)\" is not equal to \"\(actualLocalizedName as Optional)\"")
151+
let seconds2 = tz2?.secondsFromGMT() ?? 0
152152
XCTAssertEqual(seconds2, -14400, "GMT-0400 should be -14400 seconds but got \(seconds2) instead")
153153

154154
let tz3 = TimeZone(identifier: "GMT-9999")
@@ -161,8 +161,9 @@ class TestNSTimeZone: XCTestCase {
161161
XCTAssertNil(tz)
162162
// Test valid timezone abbreviation of "AST" for "America/Halifax"
163163
tz = TimeZone(abbreviation: "AST")
164-
let expectedName = "America/Halifax"
165-
XCTAssertEqual(tz?.identifier, expectedName, "expected name \"\(expectedName)\" is not equal to \"\(tz?.identifier)\"")
164+
let expectedIdentifier = "America/Halifax"
165+
let actualIdentifier = tz?.identifier
166+
XCTAssertEqual(actualIdentifier, expectedIdentifier, "expected identifier \"\(expectedIdentifier)\" is not equal to \"\(actualIdentifier as Optional)\"")
166167
}
167168

168169
func test_systemTimeZoneUsesSystemTime() {

TestFoundation/TestNSURL.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class TestNSURL : XCTestCase {
153153
}
154154
if let stringObj = obj as? String {
155155
if stringObj != got[key] {
156-
differences.append(" \(key) Expected = '\(stringObj)', Got = '\(got[key])'")
156+
differences.append(" \(key) Expected = '\(stringObj)', Got = '\(got[key] as Optional)'")
157157
}
158158
}
159159
}
@@ -442,7 +442,7 @@ class TestNSURLComponents : XCTestCase {
442442
var url = URLComponents(string: urlString)
443443
url!.port = port
444444
let receivedString = url!.string
445-
XCTAssertEqual(receivedString, expectedString, "expected \(expectedString) but received \(receivedString)")
445+
XCTAssertEqual(receivedString, expectedString, "expected \(expectedString) but received \(receivedString as Optional)")
446446
}
447447

448448
func test_url() {
@@ -454,7 +454,7 @@ class TestNSURLComponents : XCTestCase {
454454
compWithAuthority!.path = "/path/to/file with space.html"
455455
compWithAuthority!.query = "id=23&search=Foo Bar"
456456
var expectedString = "https://www.swift.org/path/to/file%20with%20space.html?id=23&search=Foo%20Bar"
457-
XCTAssertEqual(compWithAuthority!.string, expectedString, "expected \(expectedString) but received \(compWithAuthority!.string)")
457+
XCTAssertEqual(compWithAuthority!.string, expectedString, "expected \(expectedString) but received \(compWithAuthority!.string as Optional)")
458458

459459
var aURL = compWithAuthority!.url(relativeTo: baseURL)
460460
XCTAssertNotNil(aURL)
@@ -474,7 +474,7 @@ class TestNSURLComponents : XCTestCase {
474474
compWithoutAuthority.path = "path/to/file with space.html"
475475
compWithoutAuthority.query = "id=23&search=Foo Bar"
476476
expectedString = "path/to/file%20with%20space.html?id=23&search=Foo%20Bar"
477-
XCTAssertEqual(compWithoutAuthority.string, expectedString, "expected \(expectedString) but received \(compWithoutAuthority.string)")
477+
XCTAssertEqual(compWithoutAuthority.string, expectedString, "expected \(expectedString) but received \(compWithoutAuthority.string as Optional)")
478478

479479
aURL = compWithoutAuthority.url(relativeTo: baseURL)
480480
XCTAssertNotNil(aURL)

TestFoundation/TestNSXMLDocument.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class TestNSXMLDocument : XCTestCase {
161161
element.insertChildren([foo, bar], at: 1)
162162
XCTAssertEqual(element.children?[1], foo)
163163
XCTAssertEqual(element.children?[2], bar)
164-
XCTAssertEqual(element.children?[0], baz, "\(element.children?[0])")
164+
XCTAssertEqual(element.children?[0], baz)
165165

166166
let faz = XMLElement(name: "faz")
167167
element.replaceChild(at: 2, with: faz)
@@ -239,7 +239,7 @@ class TestNSXMLDocument : XCTestCase {
239239
XCTAssertEqual(element.attributes?.last, bazAttribute)
240240

241241
element.setAttributesWith(["hello": "world", "foobar": "buzbaz"])
242-
XCTAssertEqual(element.attribute(forName:"hello")?.stringValue, "world", "\(element.attribute(forName:"hello")?.stringValue)")
242+
XCTAssertEqual(element.attribute(forName:"hello")?.stringValue, "world", "\(element.attribute(forName:"hello")?.stringValue as Optional)")
243243
XCTAssertEqual(element.attribute(forName:"foobar")?.stringValue, "buzbaz", "\(element.attributes ?? [])")
244244
}
245245

0 commit comments

Comments
 (0)