2
2
// RUN: cp -R %S/Inputs/FakeUnavailableObjCFramework.framework %t
3
3
// RUN: %target-clang -dynamiclib %S/Inputs/FakeUnavailableObjCFramework.m -fmodules -F %t -framework Foundation -o %t/FakeUnavailableObjCFramework.framework/FakeUnavailableObjCFramework
4
4
// RUN: %target-codesign %t/FakeUnavailableObjCFramework.framework/FakeUnavailableObjCFramework
5
- // RUN: %target-build-swift -F %t %s -o %t/UseWeaklinkedUnavailableObjCFramework
6
- // RUN: %target-build-swift -O -F %t %s -o %t/UseWeaklinkedUnavailableObjCFramework.opt
5
+ // RUN: %target-build-swift-dylib(%t/%target-library-name(FakeUnavailableSwiftDylib)) -emit-module -emit-module-path %t/FakeUnavailableSwiftDylib.swiftmodule %S/Inputs/FakeUnavailableSwiftDylib.swift
6
+ // RUN: %target-codesign %t/%target-library-name(FakeUnavailableSwiftDylib)
7
+ // RUN: %target-build-swift %t/%target-library-name(FakeUnavailableSwiftDylib) -I %t -F %t %s -o %t/UseWeaklinkedUnavailableObjCFramework
8
+ // RUN: %target-build-swift -O %t/%target-library-name(FakeUnavailableSwiftDylib) -I %t -F %t %s -o %t/UseWeaklinkedUnavailableObjCFramework.opt
7
9
8
10
// These tests emulate deploying back to an older OS where newer APIs are not
9
11
// available by linking to an Objective-C framework where APIs have been
10
12
// annotated to only be available in the far future (version 1066.0 of all
11
13
// platforms) and then moving the framework aside so that it can't be found
12
14
// at run time.
13
15
// RUN: mv %t/FakeUnavailableObjCFramework.framework %t/FakeUnavailableObjCFramework-MovedAside.framework
16
+ // RUN: mv %t/%target-library-name(FakeUnavailableSwiftDylib) %t/%target-library-name(FakeUnavailableSwiftDylib)-MovedAside
14
17
15
18
// RUN: %target-codesign %t/UseWeaklinkedUnavailableObjCFramework
16
19
// RUN: %target-codesign %t/UseWeaklinkedUnavailableObjCFramework.opt
@@ -24,6 +27,7 @@ import StdlibUnittest
24
27
25
28
26
29
import FakeUnavailableObjCFramework
30
+ import FakeUnavailableSwiftDylib
27
31
import Foundation
28
32
29
33
// CHECK: Running
@@ -154,6 +158,59 @@ protocol SomeSwiftProtocol { }
154
158
@available ( OSX 1066 . 0 , iOS 1066 . 0 , watchOS 1066 . 0 , tvOS 1066 . 0 , * )
155
159
extension UnavailableObjCClass : SomeSwiftProtocol {
156
160
}
161
+ @available ( OSX 1066 . 0 , iOS 1066 . 0 , watchOS 1066 . 0 , tvOS 1066 . 0 , * )
162
+ extension UnavailableSwiftClass : SomeSwiftProtocol {
163
+ }
164
+
165
+ func checkSwiftProtocolConformance( ) {
166
+ // Make sure the runtime doesn't crash in the presence of a conformance
167
+ // record for a class that doesn't exsit at runtime.
168
+ let x : Any = 42
169
+ _blackHole ( x as? SomeSwiftProtocol )
170
+ }
171
+
172
+ checkSwiftProtocolConformance ( )
173
+
174
+ class ClassConformingToUnavailableSwiftProtocol : UnavailableSwiftProtocol {
175
+ func someMethod( ) {
176
+ print ( " Executed ClassConformingToUnavailableSwiftProtocol.someMethod() " )
177
+ }
178
+ }
179
+
180
+ func useClassConformingToUnavailableSwiftProtocol( ) {
181
+ let o = ClassConformingToUnavailableSwiftProtocol ( )
182
+ o. someMethod ( )
183
+
184
+ if #available( OSX 1066 . 0 , iOS 1066 . 0 , watchOS 1066 . 0 , tvOS 1066 . 0 , * ) {
185
+ let oAsUP : UnavailableSwiftProtocol = o as UnavailableSwiftProtocol
186
+ oAsUP. someMethod ( )
187
+ }
188
+ }
189
+
190
+ // CHECK-NEXT: Executed ClassConformingToUnavailableSwiftProtocol.someMethod()
191
+ useClassConformingToUnavailableSwiftProtocol ( )
192
+
193
+ class ClassThatWillBeExtendedToConformToUnavailableSwiftProtocol {
194
+ }
195
+
196
+ extension ClassThatWillBeExtendedToConformToUnavailableSwiftProtocol : UnavailableSwiftProtocol {
197
+ func someMethod( ) {
198
+ print ( " Executed ClassThatWillBeExtendedToConformToUnavailableSwiftProtocol.someMethod() " )
199
+ }
200
+ }
201
+
202
+ func useClassThatWillBeExtendedToConformToUnavailableSwiftProtocol( ) {
203
+ let o = ClassThatWillBeExtendedToConformToUnavailableSwiftProtocol ( )
204
+ o. someMethod ( )
205
+
206
+ if #available( OSX 1066 . 0 , iOS 1066 . 0 , watchOS 1066 . 0 , tvOS 1066 . 0 , * ) {
207
+ let oAsUP : UnavailableSwiftProtocol = o as UnavailableSwiftProtocol
208
+ oAsUP. someMethod ( )
209
+ }
210
+ }
211
+
212
+ // CHECK-NEXT: Executed ClassThatWillBeExtendedToConformToUnavailableSwiftProtocol.someMethod()
213
+ useClassThatWillBeExtendedToConformToUnavailableSwiftProtocol ( )
157
214
158
215
// CHECK-NEXT: Done
159
216
print ( " Done " )
0 commit comments