Skip to content

Commit 3250715

Browse files
authored
Merge pull request #34445 from lorentey/array-cannot-append-5.3
[5.3][stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray
2 parents aee95e6 + 4826224 commit 3250715

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

stdlib/public/core/Array.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ extension Array: RangeReplaceableCollection {
12271227
// elements. It reduces code size, because the following code
12281228
// can be removed by the optimizer by constant folding this check in a
12291229
// generic specialization.
1230-
if newElements is [Element] {
1230+
if S.self == [Element].self {
12311231
_internalInvariant(remainder.next() == nil)
12321232
return
12331233
}

validation-test/stdlib/ArrayNew.swift.gyb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,15 @@ ArrayTestSuite.test("BridgedToObjC.Nonverbatim.RoundtripThroughSwiftArray") {
11101110
}
11111111
}
11121112

1113+
ArrayTestSuite.test("append(contentsOf: NSArray)") {
1114+
// A stray runtime `is` test caused this particular operation to fail in 5.3.
1115+
// rdar://70448247
1116+
let nsarray: NSArray = [2, 3, 4]
1117+
var array: [Any] = [1]
1118+
array.append(contentsOf: nsarray)
1119+
expectEqual(array as? [Int], [1, 2, 3, 4])
1120+
}
1121+
11131122
ArrayTestSuite.setUp {
11141123
resetLeaksOfDictionaryKeysValues()
11151124
resetLeaksOfObjCDictionaryKeysValues()

0 commit comments

Comments
 (0)