Skip to content

Commit f0cb64d

Browse files
mdiepairspeedswift
authored andcommitted
Conform Never to Error, Equatable, Comparable, and Hashable (#16857)
1 parent eca9200 commit f0cb64d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

stdlib/public/core/Policy.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@
2828
@_frozen
2929
public enum Never {}
3030

31+
extension Never: Error {}
32+
33+
extension Never: Equatable {}
34+
35+
extension Never: Comparable {
36+
public static func < (lhs: Never, rhs: Never) -> Bool {
37+
switch (lhs, rhs) {
38+
}
39+
}
40+
}
41+
42+
extension Never: Hashable {}
43+
3144
//===----------------------------------------------------------------------===//
3245
// Standardized aliases
3346
//===----------------------------------------------------------------------===//

test/stdlib/Never.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
struct ConformsToError<T: Error> {}
4+
_ = ConformsToError<Never>()
5+
6+
struct ConformsToEquatable<T: Equatable> {}
7+
_ = ConformsToEquatable<Never>()
8+
9+
struct ConformsToComparable<T: Comparable> {}
10+
_ = ConformsToComparable<Never>()
11+
12+
struct ConformsToHashable<T: Hashable> {}
13+
_ = ConformsToHashable<Never>()

0 commit comments

Comments
 (0)