File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -177,3 +177,29 @@ func rdar_45825806() {
177
177
let s = S ( )
178
178
_ = s [ takesPtr: [ 1 , 2 , 3 ] ] // Ok
179
179
}
180
+
181
+ func test_generic_subscript_requirements_mismatch_diagnostics( ) {
182
+ struct S {
183
+ subscript< T: StringProtocol > ( _: T ) -> T { // expected-note {{where 'T' = 'Int'}}
184
+ fatalError ( )
185
+ }
186
+
187
+ subscript< T, U: Collection > ( v v: [ T ] ) -> U where U. Element == T {
188
+ fatalError ( )
189
+ }
190
+
191
+ subscript< T: Collection > ( number num: T ) -> Int where T. Element: BinaryInteger {
192
+ // expected-note@-1 {{'T.Element' = 'String'}}
193
+ return 42
194
+ }
195
+ }
196
+
197
+ var s = S ( )
198
+ _ = s [ 42 ] // expected-error {{subscript 'subscript(_:)' requires that 'Int' conform to 'StringProtocol'}}
199
+
200
+ var arr : [ Int ] = [ ]
201
+ let _: [ String ] = s [ v: arr] // expected-error {{cannot convert value of type '[Int]' to expected argument type '[String]'}}
202
+ // expected-note@-1 {{arguments to generic parameter 'Element' ('Int' and 'String') are expected to be equal}}
203
+
204
+ s [ number: [ " hello " ] ] // expected-error {{subscript 'subscript(number:)' requires that 'String' conform to 'BinaryInteger'}}
205
+ }
You can’t perform that action at this time.
0 commit comments