import Foundation
func testLinux() {
#if !os(Linux)
print("Bailing - not on Linux, this function is not relevant")
return
#endif
// OK, we're on Linux.
print("We are on Linux")
}
gives an error:
Code after 'return' will never be executed
Is this a bug? Or should I create a variable which is flipped inside the #if statement and then return later based on that? (edit - even if I do that, the warning is still present.)
#if !os(Linux)
print("Bailing - not on Linux, this function is not relevant")
#else
print("We are on Linux")
#endif
In your example, since all of the diagnostic logic happens after the conditional compilation determines what AST is built, you basically end up with the same AST as if you wrote:
print("Bailing - not on Linux, this function is not relevant")
return
print("We are on Linux")
Thanks - I suppose I was confusing the pre-processor with runtime evaluation.
I was looking for a way to exit the function early depending on platform. I imagine I should instead use an equivalent to the old Classic macOS 'Gestalt'.