Open swift-ci opened 7 years ago
Conditional compilation expressions are a function of the compiler, and not a preprocessor like in C or C++. They only apply at statement or declaration boundaries.
Comment by Martin Redington (JIRA)
I was about to open an issue for this, but found this one when searching for existing reports. My use case is
{{public protocol Disposable {
/// Dispose resource.
func dispose()
}
#if swift(>=5.4)
@resultBuilder
#else
@_functionBuilder
#endif
public struct DisposableBuilder {
public static func buildBlock(_ disposables: Disposable...) -> [Disposable] {
return disposables
}
}
}}
It is very annoying to have to duplicate (at least some of) the struct declaration within each branch of the compiler directive.
Attachment: Download
Environment
Xcode Version 8.1 (8B62) Apple Swift version 3.0.1 (swiftlang-800.0.58.6 clang-800.0.42.1) Target: x86_64-apple-macosx10.9Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, LanguageFeatureRequest | |Assignee | None | |Priority | Medium | md5: 83d297322aea89dcb9bbe5587fb84a02Issue Description:
I'm trying to use the @available attribute to mark some code as unavailable based on build settings (the use case here is feature toggling)
When the attribute is part of a complication directive `#if ... #endif` the code breaks with the error "expected declaration" shown on the #endif line
Playground attached but full code here as well: