swift
4826224d - [stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray

Commit
4 years ago
[stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray Due to a couple of unfortunate circumstances, appending an NSArray instance to an Array instance does not actually append any elements. The cause is https://github.com/apple/swift/pull/29220, which accidentally optimized away the actual loop that appends the elements in this particular case. (And only this particular case, which is why this wasn’t detected by the test suite.) When the argument to `Array.append(contentsOf:)` is of type NSArray, the `newElements is [Element]` expression is compiled into a runtime check that returns true, eliminating the subsequent loop over the remaining items of the iterator. Sadly, NSArray.underestimatedCount` currently returns 0, so the earlier _copyContents call is a noop, so no elements get added to `self` at all. Turning the `is` test into a direct equality check between the metatype instances resolves the issue. (cherry picked from commit 184367ca8f6fc7c8dd06582e8774db816479988c)
Author
Committer
Parents
Loading