forked from swiftlang/swift
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocol_conformance_collision.swift
81 lines (65 loc) · 2.13 KB
/
protocol_conformance_collision.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -o %t/newSDK %target-link-sdk-2021-version
// RUN: %target-codesign %t/newSDK
// RUN: %target-run %t/newSDK newSDK
// RUN: %target-build-swift %s -o %t/oldSDK %target-link-sdk-2020-version
// RUN: %target-codesign %t/oldSDK
// RUN: %target-run %t/oldSDK oldSDK
// REQUIRES: VENDOR=apple
// REQUIRES: executable_test
// Simulators refuse to run binaries built with an SDK newer than the simulator.
// UNSUPPORTED: DARWIN_SIMULATOR=ios
// UNSUPPORTED: DARWIN_SIMULATOR=tvos
// UNSUPPORTED: DARWIN_SIMULATOR=watchos
// UNSUPPORTED: DARWIN_SIMULATOR=xros
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime
import Accelerate
import Foundation
import StdlibUnittest
import SwiftShims
extensionCFString:Hashable{
staticvarlocalHashableCallCount=0
publicvarhashValue:Int{
Self.localHashableCallCount +=1
return(selfasString).hashValue
}
}
protocolP{
func firstHashValue()->Int
}
extensionSet:P{
func firstHashValue()->Int{
return first!.hashValue
}
}
@_optimize(none)
func firstHashValue(_ x:P)->Int{
x.firstHashValue()
}
letosHasWorkaround:Bool
// These are deliberately not the standard 9999, as we don't want to hit the
// special case where it's always available, and we don't want this check to be
// rewritten in any find/replace operations.
if #available(macOS 9998, iOS 9998, tvOS 9998, watchOS 9998,*){
osHasWorkaround =true
}else{
osHasWorkaround =false
}
lettestingOldSDK=CommandLine.arguments.last =="oldSDK"
vartests:TestSuite
if testingOldSDK {
tests =TestSuite("old SDK protocol conformance collision")
tests.test("CFString: Hashable conformance"){
_ =firstHashValue(NSSet(object:"Whatever")as!Set<CFString>)
letexpectedCallCount= osHasWorkaround ?1:0
expectEqual(expectedCallCount,CFString.localHashableCallCount)
}
}else{
tests =TestSuite("new SDK protocol conformance collision")
tests.test("CFString: Hashable conformance"){
_ =firstHashValue(NSSet(object:"Whatever")as!Set<CFString>)
expectEqual(0,CFString.localHashableCallCount)
}
}
runAllTests()