swiftlang/swift

Compiler error when extending a typealias of a partially specialized generic type

Open

#88 835 ouverte le 5 mai 2026

Voir sur GitHub
 (0 commentaires) (0 réactions) (1 assigné)Swift (10 719 forks)batch import
TypeResolverbugcompilerdeclarationsextensiongenericsgood first issueswift 5.9type checkertypealiasunexpected error

Métriques du dépôt

Stars
 (69 989 stars)
Métriques de merge PR
 (Merge moyen 7j 6h) (556 PRs mergées en 30 j)

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

Additional context Not a duplicate of #47452 , since #47452 passes a string as argument, but it is constrained to only accept Int.

Feel free to close this if mistaken.

Guide contributeur