Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tuple equality gets lost #62708

Open
DevAndArtist opened this issue Dec 20, 2022 · 2 comments
Open

Tuple equality gets lost #62708

DevAndArtist opened this issue Dec 20, 2022 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself conformances Feature → protocol: protocol conformances derived conformances Feature → protocol → conformances: derived conformances aka synthesized conformances type checker Area → compiler: Semantic analysis

Comments

@DevAndArtist
Copy link
Contributor

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

@DevAndArtist DevAndArtist added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Dec 20, 2022
@DevAndArtist
Copy link
Contributor Author

Hmm looks like #28833 got reverted and the implementation never landed. 🤔

@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler itself type checker Area → compiler: Semantic analysis conformances Feature → protocol: protocol conformances derived conformances Feature → protocol → conformances: derived conformances aka synthesized conformances and removed triage needed This issue needs more specific labels labels Dec 20, 2022
@benrimmington
Copy link
Contributor

Swift project in 2023 (variadic generics):

One early milestone will be to allow tuple types to conditionally conform to protocols like Equatable when their elements do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself conformances Feature → protocol: protocol conformances derived conformances Feature → protocol → conformances: derived conformances aka synthesized conformances type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants