-
Notifications
You must be signed in to change notification settings - Fork 10.5k
warn on empty OptionSet static constants #27089
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
Changes from all commits
1a5a47f
acb99fb
9c9a327
6152f8e
5ae0484
76a8fa6
a665524
bc109fd
1ba47ff
cc0afc0
13acf10
2104984
bc308e0
06c0571
c6063b2
2d5438d
4250d7f
b7e059d
f7f9086
138d731
d70b0a4
b276a7e
1da9215
67cd809
9cc2d65
d04663a
0ba2980
9090d7f
cba8684
3d9573f
3dba00f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// RUN: %target-typecheck-verify-swift | ||
|
||
struct SomeOptions: OptionSet { | ||
var rawValue: Int | ||
|
||
static let some = MyOptions(rawValue: 4) | ||
static let empty = SomeOptions(rawValue: 0) // expected-warning {{static property 'empty' produces an empty option set}} expected-note {{use [] to silence this warning}}{{35-48=([])}} | ||
static var otherVal = SomeOptions(rawValue: 0) | ||
|
||
let someVal = MyOptions(rawValue: 6) | ||
let option = MyOptions(float: Float.infinity) | ||
let none = SomeOptions(rawValue: 0) // expected-error {{value type 'SomeOptions' cannot have a stored property that recursively contains it}} | ||
} | ||
|
||
struct MyOptions: OptionSet { | ||
let rawValue: Int | ||
|
||
init(rawValue: Int) { | ||
self.rawValue = rawValue | ||
} | ||
|
||
init(float: Float) { | ||
self.rawValue = float.exponent | ||
} | ||
|
||
static let none = MyOptions(rawValue: 0) // expected-warning {{static property 'none' produces an empty option set}} expected-note {{use [] to silence this warning}}{{32-45=([])}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add some test cases that shouldn't cause the error? I can think of a few:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-static There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still would like you to add this last test too. :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry! I did, but then rolled it back to try to figure out where it was crashing. I think I figured it out now though. Just need to confirm it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the tests back but I had to make the non-static let of another type or else I'd get a build error because a struct cannot contain itself. Should I add that case anyways and expect the error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, right. And if it's for another type it's not a new test. I guess it's still good to add the test case and expect the one error to make sure the second one doesn't pop up. |
||
static var nothing = MyOptions(rawValue: 0) | ||
static let nope = MyOptions() | ||
static let other = SomeOptions(rawValue: 8) | ||
static let piVal = MyOptions(float: Float.pi) | ||
static let zero = MyOptions(float: 0.0) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.