XCTFail should return `Never` type
Originator: | sethfri | ||
Number: | rdar://FB7517692 | Date Originated: | 1/2/20 |
Status: | Open | Resolved: | No |
Product: | Developer Tools > XCTest | Product Version: | |
Classification: | Suggestion | Reproducible: |
Given that XCTFail immediately throws an error, it should return `Never` to let the compiler know that this is going to happen. Often when writing tests, we need to write helper functions like the following: ``` struct Type { let foo: String } func makeType(foo: String) -> Type { guard !foo.isEmpty else { XCTFail("An empty string was passed in for foo") } return Type(foo: foo) } ``` Because XCTFail _doesn't_ return `Never`, we get a compiler error that the guard will fall through without a return statement. However, it's not actually appropriate to return anything here. We can modify the code to return an Optional, but in some cases that simply isn't appropriate. Having XCTFail return `Never` will give our code clearer intention and allow us to communicate that intention to the compiler.
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!