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

[5.7][ConstraintSystem] Use witnesses for makeIterator and next refs in for-in context #61109

Merged
merged 6 commits into from Sep 15, 2022

Conversation

xedin
Copy link
Member

@xedin xedin commented Sep 14, 2022

Cherry-pick of #61091


  • Explanation:

Fixes behavior change introduced in 5.7 which goes against the original design of for-in loops
where makeIterator() and next() calls that form a loop statement should use witness of
Sequence#makeIterator and IteratorProtocol#next requirements instead of relying on overload
resolution.

For example:

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.

xedin and others added 5 commits September 14, 2022 14:02
…in for-in

Reference to `makeIterator` in for-in loop context needs to be
treated as a reference to a witness of `Sequence#makeIterator`
requirement, otherwise it could lead to problems with retroactive
conformances.
Reference to `$geneator.next` in for-in loop context needs to be
treated as a reference to a witness of `IteratorProtocol#next`
requirement, otherwise it could lead to problems with retroactive
conformances.
@xedin xedin requested a review from a team as a code owner September 14, 2022 21:07
@xedin xedin added the r5.7 label Sep 14, 2022
@xedin
Copy link
Member Author

xedin commented Sep 14, 2022

@swift-ci please test

@xedin
Copy link
Member Author

xedin commented Sep 15, 2022

@swift-ci please test

@RLovelett
Copy link
Contributor

I am using the swift version in Xcode 14.0.1 (14A400) (aka the 14.0.1 RC). Is this fix in there?

swift-driver version: 1.62.8 Apple Swift version 5.7 (swiftlang-5.7.0.127.4 clang-1400.0.29.50)
Target: x86_64-apple-macosx12.0

@AnthonyLatsis AnthonyLatsis added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.7 labels Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.7
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants