Skip to content

Conformance synthesis fails to check availability #77589

Open
@stephencelis

Description

@stephencelis

Description

Automatic synthesis of hashable, encodable, and decodable proceeds without issue when containing a nested type with an unavailable conformance.

Reproduction

The following compiles when it shouldn't:

struct G {
  var g: Int
}

@available(*, unavailable)
extension G: Encodable {
  func encode(to encoder: any Encoder) throws {
    fatalError()
  }
}

@available(*, unavailable)
extension G: Decodable {
  init(from decoder: any Decoder) throws {
    fatalError()
  }
}

struct S: Codable {
  var x = G(g: 1)
}

Another example using Hashable:

struct G: Equatable {
  var g: Int
}

@available(*, unavailable)
extension G: Hashable {
  func hash(into hasher: inout Hasher) {
    fatalError()
  }
}

struct S: Hashable {
  var x = G(g: 1)
}

Expected behavior

I expect the conformances to not be synthesized with a compile-time error.

Environment

swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: arm64-apple-macosx15.0

Additional information

No response

Metadata

Metadata

Assignees

Labels

availabilityThe @available attribute and availability checking in generalbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.derived conformancesFeature → protocol → conformances: derived conformances aka synthesized conformances

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions