Skip to content

Commit 6260113

Browse files
committed
Add implementation of SE-0185 to CHANGELOG
1 parent 92d9b3a commit 6260113

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
| Contents |
88
| :--------------------- |
9+
| [Swift 4.1](#swift-41) |
910
| [Swift 4.0](#swift-40) |
1011
| [Swift 3.1](#swift-31) |
1112
| [Swift 3.0](#swift-30) |
@@ -18,6 +19,41 @@ CHANGELOG
1819

1920
</details>
2021

22+
Swift 4.1
23+
---------
24+
25+
* [SE-0185][]
26+
27+
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`.
28+
29+
```swift
30+
public struct Point: Hashable {
31+
public let x: Int
32+
public let y: Int
33+
34+
public init(x: Int, y: Int) {
35+
self.x = x
36+
self.y = y
37+
}
38+
}
39+
40+
Point(3, 0) == Point(0, 3) // false
41+
Point(3, 0) == Point(3, 0) // true
42+
Point(3, 0).hashValue // -2942920663782199421
43+
44+
public enum Token: Hashable {
45+
case comma
46+
case identifier(String)
47+
case number(Int)
48+
}
49+
50+
Token.identifier("x") == .number(5) // false
51+
Token.identifier("x") == .identifier("x") // true
52+
Token.number(50).hashValue // -2002318238093721609
53+
```
54+
55+
If you wish to provide your own implementation of `==`/`hashValue`, you still can; a custom implementation will replace the one synthesized by the compiler.
56+
2157
Swift 4.0
2258
---------
2359

0 commit comments

Comments
 (0)