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-12709] Conditional conformance of stdlib RandomAccessCollections is false #55154

Closed
dabrahams opened this issue Apr 30, 2020 · 1 comment
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@dabrahams
Copy link
Collaborator

Previous ID SR-12709
Radar None
Original Reporter @dabrahams
Type Bug
Status Closed
Resolution Invalid
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: 433866332d6171ff5820a201ec099db7

Issue Description:

/// The total number of single-hop index steps made in our test collections.
var totalSteps = 0
/// A collection that tracks the number of single-hop index steps executed.
struct CountSteps0 : RandomAccessCollection {
 init(count: Int) { self.count = count }
 var count: Int
var startIndex: Int { 0 }
 var endIndex: Int { count }
 func index(after i: Int) -> Int { 
 totalSteps += 1
 return i + 1
 }
 func index(before i: Int) -> Int { 
 totalSteps += 1
 return i - 1
 }
 subscript(i: Int) -> Range<Int> { return 0..<9 }
}
extension Collection {
 func midPoint() -> Index { 
 index(startIndex, offsetBy: count / 2, limitedBy: endIndex)!
 }
}
let x0 = CountSteps0(count: 900)
_ = x0.midPoint()
print("steps:", totalSteps) // 0
_ = x0.joined().midPoint()
print("steps:", totalSteps) // 1350

Due to https://bugs.swift.org/browse/SR-12692 this is impossible to fix using protocol extensions. Hacks like this are needed.

@dabrahams
Copy link
Collaborator Author

FlattenCollection isn't random access

@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

1 participant