vanvoorden
(Rick van Voorden)
February 13, 2025, 8:28pm
1
I'm trying to track down some additional test cases for this compiler error. Has anyone else seen 6.1 fail to detect a legit protocol conformance when your code built from 6.0 with no errors?
My only repro for now is AsyncIteratorProtocol
… could there be something about the associated type values that is causing problems?
It seems to be something about the extension here that is causing problems… removing the extension compiles with no errors…
opened 08:19PM - 13 Feb 25 UTC
bug
triage needed
### Description
A type that conforms to a protocol builds correctly from 6.0 an… d fails on 6.1.
I'm experimenting with some MRE test cases… but I'm not able to generalize this compiler error down to something less concrete. My only repro for now is specifically on `AsyncIteratorProtocol`.
From the 6.0 toolchain I can define a concrete implementation of `AsyncIteratorProtocol`:
```swift
struct AsyncIteratorImpl<Element>: AsyncIteratorProtocol {
}
extension AsyncIteratorImpl {
func next() async throws -> Element? {
fatalError()
}
}
```
This compiles with no errors from 6.0.
This same exact code fails to compile from 6.1:
```text
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)
/Users/rick/Desktop/MyExecutable/Sources/main.swift:51:8: error: type 'AsyncIteratorImpl<Element>' does not conform to protocol 'AsyncIteratorProtocol'
49 | #if true
50 |
51 | struct AsyncIteratorImpl<Element>: AsyncIteratorProtocol {
| |- error: type 'AsyncIteratorImpl<Element>' does not conform to protocol 'AsyncIteratorProtocol'
| `- note: add stubs for conformance
52 |
53 | }
_Concurrency.AsyncIteratorProtocol.Element:2:16: note: protocol requires nested type 'Element'
1 | protocol AsyncIteratorProtocol {
2 | associatedtype Element}
| `- note: protocol requires nested type 'Element'
3 |
_Concurrency.AsyncIteratorProtocol.Failure:3:18: note: protocol requires nested type 'Failure'
1 | protocol AsyncIteratorProtocol {
2 | @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
3 | associatedtype Failure : Error = any Error}
| `- note: protocol requires nested type 'Failure'
4 |
/Users/rick/Desktop/MyExecutable/Sources/main.swift:51:8: error: type 'AsyncIteratorImpl<Element>' does not conform to protocol 'AsyncIteratorProtocol'
49 | #if true
50 |
51 | struct AsyncIteratorImpl<Element>: AsyncIteratorProtocol {
| |- error: type 'AsyncIteratorImpl<Element>' does not conform to protocol 'AsyncIteratorProtocol'
| `- note: add stubs for conformance
52 |
53 | }
_Concurrency.AsyncIteratorProtocol.Element:2:16: note: protocol requires nested type 'Element'
1 | protocol AsyncIteratorProtocol {
2 | associatedtype Element}
| `- note: protocol requires nested type 'Element'
3 |
_Concurrency.AsyncIteratorProtocol.Failure:3:18: note: protocol requires nested type 'Failure'
1 | protocol AsyncIteratorProtocol {
2 | @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
3 | associatedtype Failure : Error = any Error}
| `- note: protocol requires nested type 'Failure'
4 |
```
Removing the extension fixes the error:
```swift
struct AsyncIteratorImpl<Element>: AsyncIteratorProtocol {
func next() async throws -> Element? {
fatalError()
}
}
```
### Reproduction
```swift
struct AsyncIteratorImpl<Element>: AsyncIteratorProtocol {
}
extension AsyncIteratorImpl {
func next() async throws -> Element? {
fatalError()
}
}
```
### Expected behavior
No compiler errors on 6.1.
### Environment
Apple Swift version 6.1-dev (LLVM 36d7ebc48349af6, Swift c710b6d3de6a71b)
Target: arm64-apple-macosx15.0
Xcode Version 16.2 (16C5032a)
Toolchain: Swift 6.1 Development Snapshot 2025-02-10 (a)
### Additional information
_No response_
xwu
(Xiaodi Wu)
February 13, 2025, 9:19pm
2
Associated type inference can be brittle .
cc @Slava_Pestov
1 Like