Description
Previous ID | SR-10118 |
Radar | rdar://problem/48689254 |
Original Reporter | @beccadax |
Type | Improvement |
Status | Resolved |
Resolution | Done |
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Improvement, DiagnosticsQoI, StarterBug |
Assignee | Vercantez (JIRA) |
Priority | Medium |
md5: dd3960163b3287c2517c33c41718adda
Issue Description:
An OptionSet-conforming instance with a value of 0 behaves very strangely; for instance, contains(_:)
will always return true for it. Because of this, and because []
is the preferred syntax for an empty option set, ClangImporter removes none
members when it imports an NS_OPTIONS
enum.
However, if you write an OptionSet-conforming type in Swift, there's nothing stopping you from adding one yourself:
struct MyOptions: OptionSet {
var rawValue: Int
static let none = MyOptions(rawValue: 0)
}
It would be nice if the compiler emitted a warning when you did this. The criteria would probably be something like:
-
A call to init(rawValue:)
-
Passing the literal 0
-
In an initial value expression (Initializer, in the compiler's parlance)
-
For a static let variable
-
In a type conforming to OptionSet
-
When the variable belongs to the type it's declared within