Skip to content

Tuple equality gets lost #62708

Open
Open
@DevAndArtist

Description

@DevAndArtist

Description
Equality for tuples seems to get lost.

Steps to reproduce
Here are two examples that raise different error messages.

Example A:

protocol P {
  associatedtype A: Hashable
  associatedtype B: Hashable
  typealias C = (A, B)
}

struct S<T: P>: Equatable {
  // error: Type 'S<T>.Inner' does not conform to protocol 'Equatable'
  struct Inner: Equatable {
    let c: T.C
  }
  let inner: Inner
}

Workaround:

static func == (lhs: S<T>.Inner, rhs: S<T>.Inner) -> Bool {
  lhs.c == rhs.c
}

Example B with Optional that makes things worse:

protocol P {
  associatedtype A: Hashable
  associatedtype B: Hashable
  typealias C = Optional<(A, B)>
}

struct S<T: P>: Equatable {
  // error: Type '(T.A, T.B)' cannot conform to 'Equatable'
  static func == (lhs: Self, rhs: Self) -> Bool {
    lhs.c == rhs.c
  }
  let c: T.C
}

Workaround:

static func == (lhs: Self, rhs: Self) -> Bool {
  lhs.c?.0 == rhs.c?.0 && lhs.c?.1 == rhs.c?.1
}

Expected behavior
Both examples should compile just fine without manual implication of the == function.

Environment

  • Swift compiler version info:
    swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)
    Target: arm64-apple-macosx13.0

  • Xcode version info: Version 14.1 (14B47b)

  • Deployment target: iOS 15.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconformancesFeature → protocol: protocol conformancesderived conformancesFeature → protocol → conformances: derived conformances aka synthesized conformancestype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions