Skip to content

[5.3][stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray #34445

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stdlib/public/core/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ extension Array: RangeReplaceableCollection {
// elements. It reduces code size, because the following code
// can be removed by the optimizer by constant folding this check in a
// generic specialization.
if newElements is [Element] {
if S.self == [Element].self {
_internalInvariant(remainder.next() == nil)
return
}
Expand Down
9 changes: 9 additions & 0 deletions validation-test/stdlib/ArrayNew.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,15 @@ ArrayTestSuite.test("BridgedToObjC.Nonverbatim.RoundtripThroughSwiftArray") {
}
}

ArrayTestSuite.test("append(contentsOf: NSArray)") {
// A stray runtime `is` test caused this particular operation to fail in 5.3.
// rdar://70448247
let nsarray: NSArray = [2, 3, 4]
var array: [Any] = [1]
array.append(contentsOf: nsarray)
expectEqual(array as? [Int], [1, 2, 3, 4])
}

ArrayTestSuite.setUp {
resetLeaksOfDictionaryKeysValues()
resetLeaksOfObjCDictionaryKeysValues()
Expand Down