-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
TypeResolverbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdeclarationsFeature: declarationsFeature: declarationsextensionFeature → declarations: `extension` declarationsFeature → declarations: `extension` declarationsgenericsFeature: generic declarations and typesFeature: generic declarations and typesgood first issueGood for newcomersGood for newcomersswift 5.9type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysistypealiasFeature → type declarations: `typealias` declarationsFeature → type declarations: `typealias` declarationsunexpected errorBug: Unexpected errorBug: Unexpected error
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
TypeResolverbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdeclarationsFeature: declarationsFeature: declarationsextensionFeature → declarations: `extension` declarationsFeature → declarations: `extension` declarationsgenericsFeature: generic declarations and typesFeature: generic declarations and typesgood first issueGood for newcomersGood for newcomersswift 5.9type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysistypealiasFeature → type declarations: `typealias` declarationsFeature → type declarations: `typealias` declarationsunexpected errorBug: Unexpected errorBug: Unexpected error