You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
swift-ci opened this issue
Feb 25, 2019
· 2 comments
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler in itselfparserArea → compiler: The legacy C++ parser
// MARK: Compilesif !true {
print("this does not make sense")
} elseiftrue {
print("we double checked, and all is well")
} else {
print("all is well")
}
// MARK: Does not compileif !true {
print("this does not make sense")
} // ----- ERROR: Expected expression
#ifDEBUGelseiftrue {
print("we double checked, and all is well")
}
#endifelse { // ----- ERROR: Closure expression is unusedprint("all is well")
}
// MARK: Workaround; compilesif !true {
print("this does not make sense")
} else {
#ifDEBUGiftrue {
print("we double checked, and all is well")
}
#endifprint("all is well")
}
The above reproduces an issue I'm having with preprocessor directives/conditional compilation
The text was updated successfully, but these errors were encountered:
Swift's #if isn't the same as C's; it only works around an entire "unit" of the AST (usually a set of declarations or statements). However, it does work for switch cases, so it's possible we could make it work for else if as well. If not, we could at least improve the diagnostic.
@belkadan ah right, that makes perfect sense, thanks for the explanation. I did wonder if I was unreasonably expecting C-like conditional compilation.
In terms of impact for our project, this is small (due to the workaround above), but an improved diagnostic/having this problem covered in the Swift docs would be very helpful.
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler in itselfparserArea → compiler: The legacy C++ parser
Environment
Xcode 10.1, building for simulator, Swift 4
Additional Detail from JIRA
md5: 2afc1773f4650f1c632b59b1bc75e22e
Issue Description:
The above reproduces an issue I'm having with preprocessor directives/conditional compilation
The text was updated successfully, but these errors were encountered: