Can't switch on an implicitly unwrapped enum
| Originator: | cpickslay | ||
| Number: | rdar://19904040 | Date Originated: | 2/20/15 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | 6.1.1 |
| Classification: | Serious Bug | Reproducible: | Always |
Summary:
If you define a variable as an explicitly unwrapped enum type in swift, switching on its value results in a compile error.
Steps to Reproduce:
Define an enum:
1> enum Method: String {
2. case GET = "GET"
3. case HEAD = "HEAD"
4. case POST = "POST"
5. case PUT = "PUT"
6. case DELETE = "DELETE"
7. }
Declare an explicitly unwrapped variable of that enum's type:
9> var foo: Method!
Assign a value to that variable:
11> foo = .HEAD
Attempt to switch on that variable's value:
14> switch foo {
15. case .GET: println("get")
16. case .HEAD: println("head")
17. default: println("other")
18. }
Expected Results:
Switch should work as if the variable were a non-optional type
Actual Results:
Compiler error that the enum case is not found on the explicitly unwrapped optional type:
repl.swift:15:7: error: enum case 'GET' not found in type 'Method!'
case .GET: println("get")
^
repl.swift:16:7: error: enum case 'HEAD' not found in type 'Method!'
case .HEAD: println("head")
Version:
Xcode 6.1.1, OS X 10.10.2
Notes:
Configuration:
Attachments:
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!