Skip to content

Add implementation of SE-0185 to CHANGELOG #12447

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
Oct 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

| Contents |
| :--------------------- |
| [Swift 4.1](#swift-41) |
| [Swift 4.0](#swift-40) |
| [Swift 3.1](#swift-31) |
| [Swift 3.0](#swift-30) |
Expand All @@ -18,6 +19,41 @@ CHANGELOG

</details>

Swift 4.1
---------

* [SE-0185][]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you need to add the link to the actual proposal elsewhere in the file for this to work

Copy link
Member Author

Choose a reason for hiding this comment

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

Much to my surprise, it was already there! (Last line of https://raw.githubusercontent.com/apple/swift/master/CHANGELOG.md.)


Structs and enums that declare a conformance to `Equatable`/`Hashable` now get an automatically synthesized implementation of `==`/`hashValue`. For structs, all stored properties must be `Equatable`/`Hashable`. For enums, all enum cases with associated values must be `Equatable`/`Hashable`.

```swift
public struct Point: Hashable {
public let x: Int
public let y: Int

public init(x: Int, y: Int) {
self.x = x
self.y = y
}
}

Point(3, 0) == Point(0, 3) // false
Point(3, 0) == Point(3, 0) // true
Point(3, 0).hashValue // -2942920663782199421

public enum Token: Hashable {
case comma
case identifier(String)
case number(Int)
}

Token.identifier("x") == .number(5) // false
Token.identifier("x") == .identifier("x") // true
Token.number(50).hashValue // -2002318238093721609
```

If you wish to provide your own implementation of `==`/`hashValue`, you still can; a custom implementation will replace the one synthesized by the compiler.

Swift 4.0
---------

Expand Down