Skip to content

[Sema] Allow weak/unowned types when checking Hashable/Equatable conformance #22143

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

Merged
merged 1 commit into from
Jan 28, 2019
Merged

[Sema] Allow weak/unowned types when checking Hashable/Equatable conformance #22143

merged 1 commit into from
Jan 28, 2019

Conversation

theblixguy
Copy link
Collaborator

@theblixguy theblixguy commented Jan 26, 2019

This PR fixes an issue with Equatable and Hashable conformance checking, where it won't look through a ReferenceStorageType.

The following code works as expected now:

struct Foo: Equatable, Hashable {
    weak var foo: Bar?
    unowned var bar: Bar
}

class Bar {
   let bar: String

   init(bar: String) {
     self.bar = bar
   }
}

extension Bar: Equatable, Hashable {
  static func == (lhs: Bar, rhs: Bar) -> Bool {
        return lhs.bar == rhs.bar
  }

  func hash(into hasher: inout Hasher) {}
}

@theblixguy
Copy link
Collaborator Author

theblixguy commented Jan 26, 2019

cc @slavapestov @jrose-apple @xedin

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test case.

@slavapestov slavapestov self-assigned this Jan 26, 2019
@theblixguy
Copy link
Collaborator Author

@slavapestov Done :)

@slavapestov
Copy link
Contributor

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor

Thanks!

@slavapestov slavapestov merged commit ac557c5 into swiftlang:master Jan 28, 2019
@theblixguy theblixguy deleted the fix/look-through-reference-storage-type-equatable branch January 28, 2019 18:13
@dlindenkreuz
Copy link

dlindenkreuz commented Mar 6, 2019

Related Swift forums thread:
https://forums.swift.org/t/struct-with-weak-member-prevents-synthesized-equatable/19778

Thanks for fixing, @theblixguy! Let's hope this makes it to 5.0.

@theblixguy
Copy link
Collaborator Author

@dlindenkreuz This won't make 5.0, but will be available in 5.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants