|
1 |
| -// RUN: %target-swift-frontend -target %target-cpu-apple-macosx10.9 -typecheck -verify %s |
| 1 | +// RUN: %target-swift-frontend -typecheck -verify %s |
2 | 2 | // REQUIRES: OS=macosx
|
3 | 3 |
|
4 | 4 | struct Butt {
|
5 |
| - var setter_conditionally_available: Int { |
6 |
| - get { fatalError() } |
| 5 | + var setter_conditionally_available: Int { |
| 6 | + get { fatalError() } |
7 | 7 |
|
8 |
| - @available(macOS 10.10, *) |
9 |
| - set { fatalError() } |
10 |
| - } |
| 8 | + @available(macOS 99, *) |
| 9 | + set { fatalError() } |
| 10 | + } |
| 11 | + |
| 12 | + var setter_unavailable_on_macos: Int { |
| 13 | + get { fatalError() } |
| 14 | + |
| 15 | + @available(macOS, unavailable) |
| 16 | + set { fatalError() } |
| 17 | + } |
| 18 | + |
| 19 | + var setter_universally_unavailable: Int { |
| 20 | + get { fatalError() } |
| 21 | + |
| 22 | + @available(*, unavailable) |
| 23 | + set { fatalError() } |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +@dynamicMemberLookup |
| 28 | +struct Lens<T> { |
| 29 | + var obj: T |
| 30 | + |
| 31 | + init(_ obj: T) { |
| 32 | + self.obj = obj |
| 33 | + } |
| 34 | + |
| 35 | + subscript<U>(dynamicMember member: KeyPath<T, U>) -> Lens<U> { |
| 36 | + get { return Lens<U>(obj[keyPath: member]) } |
| 37 | + } |
| 38 | + |
| 39 | + subscript<U>(dynamicMember member: WritableKeyPath<T, U>) -> Lens<U> { |
| 40 | + get { return Lens<U>(obj[keyPath: member]) } |
| 41 | + set { obj[keyPath: member] = newValue.obj } |
| 42 | + } |
11 | 43 | }
|
12 | 44 |
|
13 | 45 | func assertExactType<T>(of _: inout T, is _: T.Type) {}
|
14 | 46 |
|
15 | 47 | @available(macOS 10.9, *)
|
16 |
| -public func unavailableSetterContext() { |
17 |
| - var kp = \Butt.setter_conditionally_available |
18 |
| - assertExactType(of: &kp, is: KeyPath<Butt, Int>.self) |
| 48 | +public func availableOnMacOS_10_9() { |
| 49 | + var kp = \Butt.setter_conditionally_available |
| 50 | + var lens = Lens(Butt()) |
| 51 | + assertExactType(of: &kp, is: KeyPath<Butt, Int>.self) |
| 52 | + _ = lens.setter_conditionally_available |
| 53 | + lens.setter_conditionally_available = Lens(1) // expected-error {{cannot assign to property: 'lens' is immutable}} |
| 54 | +} |
| 55 | + |
| 56 | +@available(macOS 99, *) |
| 57 | +public func availableOnMacOS_99() { |
| 58 | + var kp = \Butt.setter_conditionally_available |
| 59 | + var lens = Lens(Butt()) |
| 60 | + assertExactType(of: &kp, is: WritableKeyPath<Butt, Int>.self) |
| 61 | + _ = lens.setter_conditionally_available |
| 62 | + lens.setter_conditionally_available = Lens(1) |
19 | 63 | }
|
20 |
| -@available(macOS 10.10, *) |
21 |
| -public func availableSetterContext() { |
| 64 | + |
| 65 | +public func alwaysAvailableOnMacOS() { |
| 66 | + var lens = Lens(Butt()) |
| 67 | + |
| 68 | + if #available(macOS 99, *) { |
22 | 69 | var kp = \Butt.setter_conditionally_available
|
23 | 70 | assertExactType(of: &kp, is: WritableKeyPath<Butt, Int>.self)
|
| 71 | + _ = lens.setter_conditionally_available |
| 72 | + // FIXME: [availability] setter_conditionally_available should be writable in this branch |
| 73 | + lens.setter_conditionally_available = Lens(1) // expected-error {{cannot assign to property: 'lens' is immutable}} |
| 74 | + } else { |
| 75 | + var kp = \Butt.setter_conditionally_available |
| 76 | + assertExactType(of: &kp, is: KeyPath<Butt, Int>.self) |
| 77 | + _ = lens.setter_conditionally_available |
| 78 | + lens.setter_conditionally_available = Lens(1) // expected-error {{cannot assign to property: 'lens' is immutable}} |
| 79 | + } |
| 80 | + |
| 81 | + var kp2 = \Butt.setter_unavailable_on_macos |
| 82 | + assertExactType(of: &kp2, is: KeyPath<Butt, Int>.self) |
| 83 | + _ = lens.setter_unavailable_on_macos |
| 84 | + lens.setter_unavailable_on_macos = Lens(1) // expected-error {{cannot assign to property: 'lens' is immutable}} |
| 85 | + |
| 86 | + var kp3 = \Butt.setter_universally_unavailable |
| 87 | + assertExactType(of: &kp3, is: KeyPath<Butt, Int>.self) |
| 88 | + _ = lens.setter_universally_unavailable |
| 89 | + lens.setter_universally_unavailable = Lens(1) // expected-error {{cannot assign to property: 'lens' is immutable}} |
24 | 90 | }
|
25 |
| -@available(macOS 10.9, *) |
26 |
| -public func conditionalAvailableSetterContext() { |
27 |
| - if #available(macOS 10.10, *) { |
28 |
| - var kp = \Butt.setter_conditionally_available |
29 |
| - assertExactType(of: &kp, is: WritableKeyPath<Butt, Int>.self) |
30 |
| - } else { |
31 |
| - var kp = \Butt.setter_conditionally_available |
32 |
| - assertExactType(of: &kp, is: KeyPath<Butt, Int>.self) |
33 |
| - } |
| 91 | + |
| 92 | +@available(macOS, unavailable) |
| 93 | +public func unvailableOnMacOS() { |
| 94 | + var lens = Lens(Butt()) |
| 95 | + var kp = \Butt.setter_conditionally_available |
| 96 | + assertExactType(of: &kp, is: WritableKeyPath<Butt, Int>.self) |
| 97 | + _ = lens.setter_conditionally_available |
| 98 | + lens.setter_conditionally_available = Lens(1) |
| 99 | + |
| 100 | + var kp2 = \Butt.setter_unavailable_on_macos |
| 101 | + assertExactType(of: &kp2, is: WritableKeyPath<Butt, Int>.self) |
| 102 | + _ = lens.setter_unavailable_on_macos |
| 103 | + lens.setter_unavailable_on_macos = Lens(1) |
| 104 | + |
| 105 | + var kp3 = \Butt.setter_universally_unavailable |
| 106 | + assertExactType(of: &kp3, is: KeyPath<Butt, Int>.self) |
| 107 | + _ = lens.setter_universally_unavailable |
| 108 | + lens.setter_universally_unavailable = Lens(1) // expected-error {{cannot assign to property: 'lens' is immutable}} |
34 | 109 | }
|
35 | 110 |
|
36 |
| -// FIXME: Check additional unavailability conditions |
| 111 | +@available(*, unavailable) |
| 112 | +public func universallyUnavailable() { |
| 113 | + var lens = Lens(Butt()) |
| 114 | + var kp = \Butt.setter_conditionally_available |
| 115 | + assertExactType(of: &kp, is: WritableKeyPath<Butt, Int>.self) |
| 116 | + _ = lens.setter_conditionally_available |
| 117 | + lens.setter_conditionally_available = Lens(1) |
| 118 | + |
| 119 | + var kp2 = \Butt.setter_unavailable_on_macos |
| 120 | + assertExactType(of: &kp2, is: WritableKeyPath<Butt, Int>.self) |
| 121 | + _ = lens.setter_unavailable_on_macos |
| 122 | + lens.setter_unavailable_on_macos = Lens(1) |
| 123 | + |
| 124 | + var kp3 = \Butt.setter_universally_unavailable |
| 125 | + assertExactType(of: &kp3, is: KeyPath<Butt, Int>.self) |
| 126 | + _ = lens.setter_universally_unavailable |
| 127 | + lens.setter_universally_unavailable = Lens(1) // expected-error {{cannot assign to property: 'lens' is immutable}} |
| 128 | +} |
0 commit comments