|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-build-swift %s -o %t/newSDK %target-link-sdk-future-version |
| 3 | +// RUN: %target-codesign %t/newSDK |
| 4 | +// RUN: %target-run %t/newSDK newSDK |
| 5 | +// RUN: %target-build-swift %s -o %t/oldSDK %target-link-sdk-2020-version |
| 6 | +// RUN: %target-codesign %t/oldSDK |
| 7 | +// RUN: %target-run %t/oldSDK oldSDK |
| 8 | + |
| 9 | +// REQUIRES: VENDOR=apple |
| 10 | + |
| 11 | +// Simulators refuse to run binaries built with an SDK newer than the simulator. |
| 12 | +// UNSUPPORTED: DARWIN_SIMULATOR=ios |
| 13 | +// UNSUPPORTED: DARWIN_SIMULATOR=tvos |
| 14 | +// UNSUPPORTED: DARWIN_SIMULATOR=watchos |
| 15 | + |
| 16 | +import Accelerate |
| 17 | +import Foundation |
| 18 | +import StdlibUnittest |
| 19 | +import SwiftShims |
| 20 | + |
| 21 | + |
| 22 | +extension CFString: Hashable { |
| 23 | + static var localHashableCallCount = 0 |
| 24 | + public var hashValue: Int { |
| 25 | + Self.localHashableCallCount += 1 |
| 26 | + return (self as String).hashValue |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +protocol P { |
| 31 | + func firstHashValue() -> Int |
| 32 | +} |
| 33 | + |
| 34 | +extension Set: P { |
| 35 | + func firstHashValue() -> Int { |
| 36 | + return first!.hashValue |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +@_optimize(none) |
| 41 | +func firstHashValue(_ x: P) -> Int { |
| 42 | + x.firstHashValue() |
| 43 | +} |
| 44 | + |
| 45 | +let osHasWorkaround: Bool |
| 46 | +// These are deliberately NOT version 9999, as we don't want to hit the special |
| 47 | +// case where development runtimes always return true for 9999. This check needs |
| 48 | +// to be false until real version numbers are put in. |
| 49 | +if #available(macOS 99990, iOS 99990, tvOS 99990, watchOS 99990, *) { |
| 50 | + osHasWorkaround = true |
| 51 | +} else { |
| 52 | + osHasWorkaround = false |
| 53 | +} |
| 54 | + |
| 55 | +let testingOldSDK = CommandLine.arguments.last == "oldSDK" |
| 56 | + |
| 57 | +var tests: TestSuite |
| 58 | + |
| 59 | +if testingOldSDK { |
| 60 | + tests = TestSuite("old SDK protocol conformance collision") |
| 61 | + tests.test("CFString: Hashable conformance") { |
| 62 | + _ = firstHashValue(NSSet(object: "Whatever") as! Set<CFString>) |
| 63 | + |
| 64 | + let expectedCallCount = osHasWorkaround ? 1 : 0 |
| 65 | + expectEqual(expectedCallCount, CFString.localHashableCallCount) |
| 66 | + } |
| 67 | +} else { |
| 68 | + tests = TestSuite("new SDK protocol conformance collision") |
| 69 | + tests.test("CFString: Hashable conformance") { |
| 70 | + _ = firstHashValue(NSSet(object: "Whatever") as! Set<CFString>) |
| 71 | + |
| 72 | + expectEqual(0, CFString.localHashableCallCount) |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +runAllTests() |
0 commit comments