[swift-evolution] [Proposal] Swift 2.2: #if swift language version

David Farler dfarler at apple.com
Sat Dec 19 16:08:13 CST 2015

> On Dec 19, 2015, at 13:48, Michel Fortin <michel.fortin at michelf.ca> wrote:
>> Le 18 déc. 2015 à 15:22, David Farler via swift-evolution <swift-evolution at swift.org> a écrit :
>> #if swift("2.2")
>> print("Hello")
>> #else
>> this code will not parse or emit diagnostics
>> #endif
> This is a change from how the #if directive currently works. Currently, it's a syntax error to write this:
>    #if DEBUG
>    @abaraka func test() {}
>    #endif
> even if DEBUG is false because the content is parsed regardless and @abaraka is not a valid attribute. The syntax inside the #if/#endif must be valid for the parser.
> So this proposal implies a change in how #if is parsed. Should it works like the C preprocessor?
> -- 
> Michel Fortin
> michel.fortin at michel

Yes, that's right, it is a change but only for this new directive because one of its uses is to control exposure to syntax or API changes. Other build configurations such as 'os' and 'arch' will be unaffected. 

I myself wouldn't want build configs to act like the C preprocessor, although that kind of change is probably out of this proposal's scope anyway, IMO.


More information about the swift-evolution mailing list