Description
Description
In Swift 5.8, when attempting to inherit from a protocol with primary associated types specified and providing a typealias for the associated type, the code fails to compile with the error "Cannot inherit from protocol type with generic argument 'P'."
Steps to reproduce
- Define a protocol
P
with a primary associated typeT
. - Attempt to create a struct
F
that inherits fromP<Int>
and provide a typealias for the associated type.
protocol P<T> {
associatedtype T
}
// Cannot inherit from protocol type with generic argument 'P<Int>'
struct F: P<Int> {}
Expected behavior
The code should compile without any errors, as mentioned in SE-0346
In the inheritance clause of a concrete type, for example:
struct Lines : Collection<String> { ... }In this position it is sugar for specifying the associated type witness, similar to explicitly declaring a typealias:
struct Lines : Collection { typealias Element = String }
Environment
-
Swift compiler version info:
swift-driver version: 1.75.2 Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)
Target: x86_64-apple-macosx13.0 -
Xcode version info:
Xcode 14.3.1
Build version 14E300c -
Deployment target: N/A
Other Information