Files
swift-mirror/test/Parse/ConditionalCompilation/can_import_sdk.swift
Robert Widmann 75a83da03e Implement SE-0075: CanImport
This implementation required a compromise between parser
performance and AST structuring.  On the one hand, Parse
must be fast in order to keep things in the IDE zippy, on
the other we must hit the disk to properly resolve 'canImport'
conditions and inject members of the active clause into the AST.
Additionally, a Parse-only pass may not provide platform-specific
information to the compiler invocation and so may mistakenly
activate or de-activate branches in the if-configuration decl.

The compromise is to perform condition evaluation only when
continuing on to semantic analysis.  This keeps the parser quick
and avoids the unpacking that parse does for active conditions
while still retaining the ability to see through to an active
condition when we know we're moving on to semantic analysis anyways.
2017-08-28 18:35:06 -04:00

75 lines
1.4 KiB
Swift

// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify %s
// REQUIRES: objc_interop
class Unique {}
#if canImport(Swift)
#else
class Unique {} // This should not happen
#endif
#if canImport(Swiftz)
class Unique {} // This should not happen
#else
#endif
#if canImport(UIKit)
import UIKit
class MyView : UIView {}
#elseif canImport(AppKit)
import AppKit
class MyView : NSView {}
#else
class Unique {} // This should not happen
#endif
#if canImport(Foundation) || canImport(Foundation)
import Foundation
#else
class Unique {} // This should not happen
#endif
#if canImport(Foundation) && canImport(Foundation)
import Foundation
#else
class Unique {} // This should not happen
#endif
#if !canImport(Swiftz)
#if canImport(UIKit)
import UIKit
#else
class Unique {} // This should not happen
#endif
#else
class Unique {} // This should not happen
#endif
func keepOn(keepingOn : () -> ()) {
#if canImport(Foundation)
keepingOn()
#else
class Unique {} // This should not happen
#endif
}
keepOn {
#if !canImport(Swift) || canImport(Foundation)
print("")
#elseif canImport(Swiftz)
class Unique {} // This should not happen
#else
class Unique {} // This should not happen
#endif
let object : NSObject
#if canImport(Foundation)
object = NSObject()
#else
object = "This should not happen"
#endif
print(object)
}