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-1466] Collection.Indices doesn't expose Comparable elements #44075

Closed
glessard opened this issue May 10, 2016 · 4 comments
Closed

[SR-1466] Collection.Indices doesn't expose Comparable elements #44075

glessard opened this issue May 10, 2016 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@glessard
Copy link
Contributor

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

Apple Swift version 3.0-dev (LLVM dffa09ffd8, Clang 9f0d189820, Swift 1c720b8)
(on OS X)

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: f99df57548a484701b7b53e48286a839

Issue Description:

Comparable is a requirement of Collection.Index, yet the Sequence returned by Collection.Indices hides that its element type conforms to Comparable.

func f<C: Collection>(c: C) {
  let s = c.startIndex
  for i in c.indices {
    if s == i { break }
    // Argument type 'C.Indices.Iterator.Element' does not conform to expected type 'Comparable'
  }
}

I can restrict the generic parameter thusly:

func g<C: Collection where C.Indices.Iterator.Element == C.Index>(c: C) {
  let s = c.startIndex
  for i in c.indices {
    if s == i { break } // no problem
  }
}

It seems this should always be true.

@glessard
Copy link
Contributor Author

Even less useful:

func function<C: Collection>(c: C) {
  for index in c.indices {
    _ = c[index] // Cannot subscript a value of type 'C' with an index of type 'C.Indices.Iterator.Element'
  }
}

@Dante-Broggi
Copy link
Contributor

I think this would have been fixed in Swift 4.2, with SE-0143 (Conditional Conformances).

@glessard
Copy link
Contributor Author

It was actually fixed as far back as Swift 4.0.2. Thanks for the reminder.

@glessard
Copy link
Contributor Author

Fixed in Swift 4.0.2

@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