Skip to content

Commit d5b4e28

Browse files
committed
NSCalendar: Change the type of force casting in func _symbols(_:) -> [String].
Despite `CFDateFormatterCopyProperty(_:_:)` returns `CFArrayRef`, the compiler on Linux assume that the type is `_NSCFArray` and fails to cast even though they are compatible. See https://bugs.swift.org/browse/SR-10638 .
1 parent f9b18eb commit d5b4e28

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Foundation/NSCalendar.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ open class NSCalendar : NSObject, NSCopying, NSSecureCoding {
329329
private func _symbols(_ key: CFString) -> [String] {
330330
let dateFormatter = CFDateFormatterCreate(kCFAllocatorSystemDefault, locale?._cfObject, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle)
331331
CFDateFormatterSetProperty(dateFormatter, kCFDateFormatterCalendarKey, _cfObject)
332-
let result = (CFDateFormatterCopyProperty(dateFormatter, key) as! CFArray)._swiftObject
332+
let result = (CFDateFormatterCopyProperty(dateFormatter, key) as! NSArray)._swiftObject
333333
return result.map {
334334
return ($0 as! NSString)._swiftObject
335335
}

TestFoundation/TestCalendar.swift

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class TestCalendar: XCTestCase {
2626
("test_currentCalendarRRstability", test_currentCalendarRRstability),
2727
("test_hashing", test_hashing),
2828
("test_dateFromDoesntMutate", test_dateFromDoesntMutate),
29+
("test_sr10638", test_sr10638),
2930
]
3031
}
3132

@@ -254,6 +255,12 @@ class TestCalendar: XCTestCase {
254255
XCTAssertEqual(calendarCopy.timeZone, calendar.timeZone)
255256
XCTAssertEqual(calendarCopy, calendar)
256257
}
258+
259+
func test_sr10638() {
260+
// https://bugs.swift.org/browse/SR-10638
261+
let cal = Calendar(identifier: .gregorian)
262+
XCTAssertGreaterThan(cal.eraSymbols.count, 0)
263+
}
257264
}
258265

259266
class TestNSDateComponents: XCTestCase {

0 commit comments

Comments
 (0)