forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic_replacement_opaque_result2.swift
60 lines (46 loc) · 1.19 KB
/
dynamic_replacement_opaque_result2.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
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -o %t/main %target-rpath(%t) %s -swift-version 5
// RUN: %target-codesign %t/main
// RUN: %target-run %t/main | %FileCheck %s
// RUN: %target-build-swift -o %t/main %target-rpath(%t) %s -swift-version 5 -enable-library-evolution
// RUN: %target-codesign %t/main
// RUN: %target-run %t/main | %FileCheck %s
// REQUIRES: executable_test
// REQUIRES: swift_test_mode_optimize_none
// REQUIRES: CPU=arm64 || CPU=arm64e || CPU=x86_64
public protocol Assoc {
associatedtype A = Int
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
func act() -> A
}
func testAssociatedType<T: Assoc> (_ t: T) {
print(T.A.self)
}
protocol P {
}
extension Int : P {
}
struct Pair : P {}
struct Test : Assoc {
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
dynamic func act() -> some P {
return 1
}
}
extension Test {
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@_dynamicReplacement(for: act)
func act_r() -> some P {
return Pair()
}
}
func test() {
let t = Test()
// CHECK: Pair
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
testAssociatedType(t)
} else {
print("Pair")
}
}
test()