Skip to content

[CSRanking] Adjust ranking of makeIterator overloads in for-in context #61075

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

Closed
wants to merge 1 commit into from

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Sep 13, 2022

Prefer an overload of makeIterator that satisfies
Sequence#makeIterator requirement when .makeIterator()
is implicitly injected after sequence expression in for-in
loop context.

This helps to avoid issues related to conditional conformances
to Sequence that add makeIterator preferred by overloading
rules that could change behavior i.e.:

extension Array where Element == Double {
  func makeIterator() -> Array<Int>.Iterator {
    return [1, 2, 3].makeIterator()
  }
}

for i in [4.0, 5.0, 6.0] {
  print(i)
}

makeIterator declared in the Array extension is not a witness to Sequence#makeIterator and shouldn't be used because that would change runtime behavior.

Resolves: #60514
Resolves: #60958

@xedin xedin requested a review from hborla September 13, 2022 17:18
@xedin
Copy link
Contributor Author

xedin commented Sep 13, 2022

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Sep 13, 2022

@swift-ci please test source compatibility

…ntext

Prefer an overload of `makeIterator` that satisfies
`Sequence#makeIterator` requirement when `.makeIterator()`
is implicitly injected after sequence expression in `for-in`
loop context.

This helps to avoid issues related to conditional conformances
to `Sequence` that add `makeIterator` preferred by overloading
rules that could change behavior i.e.:

```swift
extension Array where Element == Double {
  func makeIterator() -> Array<Int>.Iterator {
    return [1, 2, 3].makeIterator()
  }
}

for i in [4.0, 5.0, 6.0] {
  print(i)
}
```

`makeIterator` declared in the `Array` extension is not a witness
to `Sequence#makeIterator` and shouldn't be used because that would
change runtime behavior.

Resolves: swiftlang#60514
Resolves: swiftlang#60958
@xedin
Copy link
Contributor Author

xedin commented Sep 13, 2022

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Sep 13, 2022

@swift-ci please test source compatibility

Copy link
Collaborator

@AnthonyLatsis AnthonyLatsis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind sticking to the issue-* format for file names? This is the one I'm planning to use once I start renaming sr* files.

@xedin
Copy link
Contributor Author

xedin commented Sep 13, 2022

@AnthonyLatsis Sure, let's let the source compat run and I'm going to rename before merging.

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.

[Regression] Ambiguous makeIterator() in 5.7 Sequence/Iterator conformance broken in 5.7
3 participants