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-10487] Misleading about the swift doc. #52887

Open
swift-ci opened this issue Apr 15, 2019 · 1 comment
Open

[SR-10487] Misleading about the swift doc. #52887

swift-ci opened this issue Apr 15, 2019 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. documentation standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-10487
Radar None
Original Reporter jwang (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug, Documentation
Assignee None
Priority Medium

md5: a2b9e0916b50d3b08aeae4427512a1f2

Issue Description:

for the Array method:

 @inlinable public func index(_ i: Int, offsetBy distance: Int, limitedBy limit: Int) -> Int?

the Doc gives an example:

/// let numbers = [10, 20, 30, 40, 50]
/// if let i = numbers.index(numbers.startIndex,
/// offsetBy: 4,
/// limitedBy: numbers.endIndex) {

/// print(numbers[i])

/// }

why it uses `numbers.endIndex` for the `limit` param, it obvious wrong, we should use `numbers.endIndex-1`, it works here because the `distance` param is 4, and it will crash if the `distance` is 5.

And if I search `limitedBy` in the swift project, there are a lot of places use `endIndex` as the param.

I think these are bad examples, we should fix it.

@belkadan
Copy link
Contributor

cc @natecook1000, @krilnon, @lorentey

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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. documentation standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

2 participants