Skip to content

Fix Data.count’s setter #2601

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 3 commits into from
Apr 14, 2020
Merged

Conversation

lorentey
Copy link
Member

@lorentey lorentey commented Jan 9, 2020

(This was ported from the overlay fix in swiftlang/swift#28919)

Data provides a settable count property. Its expected behavior is undocumented, but based on the implementation, it is intended to zero-extend (or truncate) the collection to the specified length.

This does not work correctly if we start with an empty Data and we try to increase the count by a small integer:

import Foundation

var d = Data()
d.count = 2
print(d.count) // ⟹ 0 ⁉️

d.count = 100
print(d.count) // ⟹ 100 ✓

It looks like this bug was introduced with the Data overhaul that shipped in Swift 5.

(This issue was uncovered by swiftlang/swift#28918.)

rdar://58134026

@lorentey lorentey requested a review from phausler January 9, 2020 02:01
@lorentey
Copy link
Member Author

lorentey commented Jan 9, 2020

@swift-ci test

@lorentey
Copy link
Member Author

lorentey commented Jan 9, 2020

D'oh.

/home/buildnode/jenkins/workspace/swift-corelibs-foundation-PR-Linux/swift-corelibs-foundation/TestFoundation/TestNSData.swift:4550:18: error: use of unresolved identifier 'expectEqualSequence'
21:43:01                  expectEqualSequence(
21:43:01                  ^~~~~~~~~~~~~~~~~~~
21:43:01 /home/buildnode/jenkins/workspace/swift-corelibs-foundation-PR-Linux/swift-corelibs-foundation/TestFoundation/TestNSData.swift:4574:18: error: use of unresolved identifier 'expectEqualSequence'
21:43:01                  expectEqualSequence(
21:43:01                  ^~~~~~~~~~~~~~~~~~~

Data provides a settable `count` property. Its expected behavior is undocumented, but based on the implementation, it is intended to zero-extend (or truncate) the collection to the specified length.

This does not work correctly if we start with an empty Data and we try to increase the count by a small integer:

```
import Foundation

var d = Data()
d.count = 2
print(d.count) // ⟹ 0 ⁉️

d.count = 100
print(d.count) // ⟹ 100 ✓
```

It looks like this bug was introduced with the Data overhaul that shipped in Swift 5.

(This issue was uncovered by swiftlang/swift#28918.)

rdar://58134026
@lorentey lorentey force-pushed the fix-Data.count-setter branch from 2f61737 to 6201f62 Compare January 9, 2020 23:43
@lorentey
Copy link
Member Author

lorentey commented Jan 9, 2020

@swift-ci test

@lorentey
Copy link
Member Author

@swift-ci please test linux platform

@lorentey
Copy link
Member Author

15:35:26 Failing Tests (1):
15:35:26     Swift(linux-x86_64) :: stdlib/Arrays.swift.gyb

This looks unrelated.

@spevans
Copy link
Contributor

spevans commented Jan 11, 2020

@swift-ci test linux

@lorentey
Copy link
Member Author

@swift-ci test

@lorentey lorentey requested a review from millenomi January 25, 2020 01:39
@spevans
Copy link
Contributor

spevans commented Jan 25, 2020

@swift-ci test linux

@lorentey
Copy link
Member Author

@swift-ci test

@lorentey
Copy link
Member Author

@swift-ci test macOS platform

@spevans
Copy link
Contributor

spevans commented Apr 14, 2020

@lorentey the macOS testing doesn't currently work correctly on this repo so the failure here can be ignored.

@lorentey lorentey merged commit ebf7f50 into swiftlang:master Apr 14, 2020
@lorentey lorentey deleted the fix-Data.count-setter branch April 14, 2020 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants