Swift compiler fails on #if / @objc mix

Originator:twiomood
Number:rdar://23487944 Date Originated:10-Nov-2015 02:00 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7.2 b3
Classification:Bug Reproducible:Always
 
Summary:
If you use #if to disable building a file in a particular configuration, and that file contains @objc, the build will spuriously fail.

Steps to Reproduce:
- Download the attached sample
- Try to compile it:

xcrun swift if-objc.swift -o if-objc

Expected Results:
It should compile w/ no symbols emitted since the entire file is #if'd out

Actual Results:
if-objc.swift:14:2: error: @objc attribute used without importing module 'Foundation'

(even though Foundation was imported, so presumably the Swift compiler's lack of textual processing of #if means it is manually disabling compiler features as they are invoked and @objc was missed).


Version:
Xcode 7.2b3

Notes:


Configuration:
All

Example:

/*
Radar 23487944

% xcrun swift if-objc.swift -o if-objc
if-objc.swift:14:2: error: @objc attribute used without importing module 'Foundation'
@objc public protocol FooProtocol {
~^~~~

*/

#if FOO_ENABLED

import Foundation
@objc public protocol FooProtocol {
	
}

@objc public class Foo : NSObject, FooProtocol {
	
}

#endif

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!