Skip to content
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

[SR-4240] drop(while:) after prefix() on pure Sequence looses the prefix #46823

Closed
palimondo mannequin opened this issue Mar 14, 2017 · 9 comments
Closed

[SR-4240] drop(while:) after prefix() on pure Sequence looses the prefix #46823

palimondo mannequin opened this issue Mar 14, 2017 · 9 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@palimondo
Copy link
Mannequin

palimondo mannequin commented Mar 14, 2017

Previous ID SR-4240
Radar None
Original Reporter @palimondo
Type Bug
Status Closed
Resolution Done
Environment

Swift 3.1beta

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug, 3.1Regression
Assignee @CodaFi
Priority Medium

md5: cee58ba90aa08a68ae18b33517c07038

Issue Description:

Looking at the source code, I believe the #4346 introduced a bug in stdlib/public/core/Sequence.swift, where the calling drop(while: ) after prefix() on a pure Sequence (Collections override this implementation) would loose the prefix, because in the internal drop(while: ) override grabs the underlying base iterator from _PrefixSequence and just wraps it in the _DropWhileSequence.

@palimondo
Copy link
Mannequin Author

palimondo mannequin commented Mar 14, 2017

I don’t have Swift 3.1 to test this myself, but I think this would be the test case:

let xs = sequence(first: 1, next: {$0 < 10 ? $0 + 1 : nil}) // Equivalent to 1...10
let ys = xs.prefix(3).drop(while: {$0 < 7})

Array(ys) // should be [], but I guess it’s [7, 8, 9, 10]

Pinging CodaFi (JIRA User) who introduced this bug addressing comments by @gribozavr.

@CodaFi
Copy link
Member

CodaFi commented Mar 14, 2017

#8087

@CodaFi
Copy link
Member

CodaFi commented Mar 16, 2017

This tracks 3.1 #8141

@dabrahams
Copy link
Collaborator

Works for me:

(swift) let xs = sequence(first: 1, next: {$0 < 10 ? $0 + 1 : nil}) // Equivalent to 1...10
// xs : UnfoldSequence<Int, (Int?, Bool)> = Swift.UnfoldSequence<Swift.Int, (Swift.Optional<Swift.Int>, Swift.Bool)>(_state: (Optional(1), true), _next: (Function), _done: false)
(swift) let ys = xs.prefix(3).drop(while: {$0 < 7})
// ys : AnySequence<Int> = Swift.AnySequence<Swift.Int>(_box: Swift._SequenceBox<Swift.AnySequence<Swift.Int>>)
(swift)
(swift) Array(ys)
// r0 : Array<Int> = []
(swift)

@palimondo
Copy link
Mannequin Author

palimondo mannequin commented Mar 20, 2017

@dabrahams, looks like you've tested this on master after 81968e2 already landed… Should I reopen this? Or did you mean to resolve it as fixed instead of can't reproduce?

@dabrahams
Copy link
Collaborator

You're quite right; this should be resolved as fixed. I see that shipping Swift gets this wrong. I don't really understand why, but I suppose it doesn't matter.

@palimondo
Copy link
Mannequin Author

palimondo mannequin commented Mar 28, 2017

@dabrahams What went wrong, process-wise, that this shipped in 3.1?! //@airspeedswift

@palimondo
Copy link
Mannequin Author

palimondo mannequin commented May 1, 2017

The fix was integrated into Swift 3.1 branch and is waiting for a release in version 3.1.1. This hasn't shipped yet as of Xcode 8.3.2.

@palimondo
Copy link
Mannequin Author

palimondo mannequin commented May 3, 2017

I stand corrected. The fix is in Xcode 8.3.2. Sorry for the confusion. Closing.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

2 participants