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
Sequence/Iterator conformance broken in 5.7 #60514
Comments
@hborla I have a feeling this can be related to primary associated type changes that landed in 5.7. Since you worked on those, would you have a moment to give some guidance on what caused the issue? Thanks! |
@MaxDesiatov the type checking of @xedin I remember there was another ambiguity related to that change. Any ideas here? |
I've also tried adding a constraint on public protocol VectorSectionReader: Sequence
where Element == Result<Item, Error>, Iterator == VectorSectionIterator<Self> {
// ...
} That makes it complain about circular references between
|
The issue here is that |
@MaxDesiatov Adding that same-type requirement on the extension fixes it: extension VectorSectionReader where Iterator == VectorSectionIterator<Self> {
__consuming public func makeIterator() -> VectorSectionIterator<Self> {
VectorSectionIterator(reader: self, count: count)
}
public func collect() throws -> [Item] {
var items: [Item] = []
items.reserveCapacity(Int(count))
for result in self {
try items.append(result.get())
}
return items
}
} |
Perfect, thank you! I guess I can keep this open as a regression? |
@MaxDesiatov Does it make sense for @hborla |
In this case default I'm not the original author of the code, but I'll let @kateinoigakukun correct me if I'm wrong: the whole purpose of |
@MaxDesiatov as far as I remember, Max understands my intention for the code correctly. So it seems ok with Holly's suggestion in our case. |
…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: apple#60514 Resolves: apple#60958
…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: apple#60514 Resolves: apple#60958
Describe the bug
Code utilizing
Sequence
andIterator
protocols that worked in previous versions of Swift no longer type-checks in 5.7 snapshots.Steps To Reproduce
Try to build WasmTransformer with Xcode 14.0 beta 5.
Expected behavior
This code type-checks and builds as it did Swift 5.5/5.6
Screenshots
Environment (please fill out the following information)
swiftlang/swift:nightly-5.7-focal
image and6fa8c6b08e85
hash.Additional context
Here's the code snippet (not self-contained, but I hope it helps to pinpoint the issue) that causes these new errors:
The text was updated successfully, but these errors were encountered: