Xcode-7 (7A121l): «throwable» init functions shouldn't required initialization of properties before throwing
| Originator: | me | ||
| Number: | rdar://21514477 | Date Originated: | 23-Jun-2015 05:35 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode-7 (7A121l) |
| Classification: | Serious Bug | Reproducible: | Always |
Summary:
An `init` function that `throws` should be required to initialize all properties before throwing.
Steps to Reproduce:
put this code in a playground:
enum TestError : ErrorType {
case TestErr
}
class Test {
let property1: String
let property2: String?
init(shouldThrow: Boolean) throws {
guard shouldThrow == false else {
throw TestError.TestErr
}
self.property1 = "bleh"
self.property2 = nil
}
Expected Results:
Code compiles
Actual Results:
The compiler throws an error stating that all stored properties must of a class instance must be initialized before throwing from an initializer.
Regression:
Describe circumstances where the problem occurs or does not occur, such as software versions and/or hardware configurations.
Notes:
There’s no point in requiring that properties must be initialized before throwing since the whole point of a «throwable» initializer is to «fail» when certain criteria is not met and thus provide a clean path to the failure.
If anything at least accept `defer` inside init functions with let
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!