Skip to content

Commit e032c64

Browse files
committed
Tests: Add tests exercising subscripts to availability_accessors.swift.
Some of the test cases demonstrate the issue reported in rdar://130487998.
1 parent 0f0be6b commit e032c64

File tree

1 file changed

+56
-4
lines changed

1 file changed

+56
-4
lines changed

test/Sema/availability_accessors.swift

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,51 @@ struct BaseStruct<T: ValueProto> {
6565

6666
var unavailableGetter: T {
6767
@available(*, unavailable)
68-
get { fatalError() } // expected-note 62 {{getter for 'unavailableGetter' has been explicitly marked unavailable here}}
68+
get { fatalError() } // expected-note 63 {{getter for 'unavailableGetter' has been explicitly marked unavailable here}}
6969
set {}
7070
}
7171

7272
var unavailableSetter: T {
7373
get { .defaultValue }
7474
@available(*, unavailable)
75-
set { fatalError() } // expected-note 37 {{setter for 'unavailableSetter' has been explicitly marked unavailable here}}
75+
set { fatalError() } // expected-note 38 {{setter for 'unavailableSetter' has been explicitly marked unavailable here}}
7676
}
7777

7878
var unavailableGetterAndSetter: T {
7979
@available(*, unavailable)
80-
get { fatalError() } // expected-note 62 {{getter for 'unavailableGetterAndSetter' has been explicitly marked unavailable here}}
80+
get { fatalError() } // expected-note 63 {{getter for 'unavailableGetterAndSetter' has been explicitly marked unavailable here}}
8181
@available(*, unavailable)
82-
set { fatalError() } // expected-note 37 {{setter for 'unavailableGetterAndSetter' has been explicitly marked unavailable here}}
82+
set { fatalError() } // expected-note 38 {{setter for 'unavailableGetterAndSetter' has been explicitly marked unavailable here}}
8383
}
8484
}
8585

86+
struct SubscriptHelper {
87+
subscript<T>(available t: T) -> () {
88+
get { }
89+
set { }
90+
}
91+
92+
subscript<T>(unavailableGetter t: T) -> () {
93+
@available(*, unavailable)
94+
get { } // expected-note {{getter for 'subscript(unavailableGetter:)' has been explicitly marked unavailable here}}
95+
set { }
96+
}
97+
98+
subscript<T>(unavailableSetter t: T) -> () {
99+
get { }
100+
@available(*, unavailable)
101+
set { } // expected-note {{setter for 'subscript(unavailableSetter:)' has been explicitly marked unavailable here}}
102+
}
103+
104+
subscript<T>(unavailableGetterAndSetter t: T) -> () {
105+
@available(*, unavailable)
106+
get { } // expected-note {{getter for 'subscript(unavailableGetterAndSetter:)' has been explicitly marked unavailable here}}
107+
@available(*, unavailable)
108+
set { } // expected-note {{setter for 'subscript(unavailableGetterAndSetter:)' has been explicitly marked unavailable here}}
109+
}
110+
111+
}
112+
86113
@discardableResult func takesInOut<T>(_ t: inout T) -> T {
87114
return t
88115
}
@@ -184,6 +211,31 @@ func testLValueAssignments_Class(_ someValue: ClassValue) {
184211
x.unavailableGetterAndSetter[0].b = 1 // expected-error {{getter for 'unavailableGetterAndSetter' is unavailable}}
185212
}
186213

214+
func testSubscripts(_ s: BaseStruct<StructValue>) {
215+
var x = SubscriptHelper()
216+
217+
x[available: s.available] = ()
218+
x[available: s.unavailableGetter] = () // FIXME: missing diagnostic for getter
219+
// FIXME: spurious diagnostic for setter
220+
x[available: s.unavailableSetter] = () // expected-error {{setter for 'unavailableSetter' is unavailable}}
221+
// FIXME: spurious diagnostic for setter
222+
x[available: s.unavailableGetterAndSetter] = () // expected-error {{setter for 'unavailableGetterAndSetter' is unavailable}}
223+
224+
_ = x[available: s.available]
225+
_ = x[available: s.unavailableGetter] // expected-error {{getter for 'unavailableGetter' is unavailable}}
226+
_ = x[available: s.unavailableSetter]
227+
_ = x[available: s.unavailableGetterAndSetter] // expected-error {{getter for 'unavailableGetterAndSetter' is unavailable}}
228+
229+
x[unavailableGetter: s.available] = ()
230+
_ = x[unavailableGetter: s.available] // expected-error {{getter for 'subscript(unavailableGetter:)' is unavailable}}
231+
232+
x[unavailableSetter: s.available] = () // expected-error {{setter for 'subscript(unavailableSetter:)' is unavailable}}
233+
_ = x[unavailableSetter: s.available]
234+
235+
x[unavailableGetterAndSetter: s.available] = () // expected-error {{setter for 'subscript(unavailableGetterAndSetter:)' is unavailable}}
236+
_ = x[unavailableGetterAndSetter: s.available] // expected-error {{getter for 'subscript(unavailableGetterAndSetter:)' is unavailable}}
237+
}
238+
187239
func testDiscardedKeyPathLoads_Struct() {
188240
let a = [0]
189241
var x = BaseStruct<StructValue>()

0 commit comments

Comments
 (0)