Open
Description
Description
When creating a typealias that partially specializes a generic type, the compiler generates an error when attempting to extend that type via the typealias.
Steps to reproduce
Create a Generic type with two type parameters.
struct Field<Tag,Value> {
let tag: Tag
let value: Value
}
Define a typealias which specializes one of the type parameters as such :
typealias IntField<Tag> = Field<Tag,Int>
Define an extension based on the typealias:
extension IntField {
func adding(_ value: Int) -> Self {
Field(tag: tag, value: self.value + value)
}
}
Expected behavior
I would expect this code to compile.
Instead the compiler complained: "Binary operator '+' cannot be applied to operands of type 'Value' and 'Int'"
If instead of extending the typealias, I extend the type directly it compiles fine as such:
extension Field where Value == Int {
func adding(_ value: Int) -> Self {
Field(tag: tag, value: self.value + value)
}
}
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)
- Xcode version info: Xcode 14.3.1 Build version 14E300c
- Deployment target: macOS Playground
Metadata
Metadata
Assignees
Labels
A deviation from expected or documented behavior. Also: expected but undesirable behavior.The Swift compiler itselfFeature: declarationsFeature → declarations: `extension` declarationsFeature: generic declarations and typesGood for newcomersArea → compiler: Semantic analysisFeature → type declarations: `typealias` declarationsBug: Unexpected error