File tree Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -318,3 +318,24 @@ extension Collection {
318
318
func keypathToFunctionWithOptional( ) {
319
319
_ = Array ( " " ) . prefix ( 1 ... 4 , while: \. isNumber) // Ok
320
320
}
321
+
322
+ func test_new_key_path_type_requirements( ) {
323
+ struct V: ~ Copyable {
324
+ }
325
+
326
+ struct S: ~ Copyable {
327
+ var x : Int
328
+ var v : V
329
+ }
330
+
331
+ _ = \S . x // expected-error {{key path cannot refer to noncopyable type 'S'}}
332
+ _ = \S . v
333
+ // expected-error@-1 {{key path cannot refer to noncopyable type 'S'}}
334
+ // expected-error@-2 {{key path cannot refer to noncopyable type 'V'}}
335
+
336
+ func test< R> ( _: KeyPath < R , Int > ) { } // expected-note {{'where R: Copyable' is implicit here}}
337
+
338
+ test ( \S . x)
339
+ // expected-error@-1 {{key path cannot refer to noncopyable type 'S'}}
340
+ // expected-error@-2 {{local function 'test' requires that 'S' conform to 'Copyable'}}
341
+ }
Original file line number Diff line number Diff line change @@ -39,11 +39,18 @@ struct C {
39
39
40
40
// rdar://109287447
41
41
public func testKeypath< V: ~ Copyable> ( m: consuming M < V > ) {
42
- _ = m [ keyPath: \. nc] // expected-error {{key path cannot refer to noncopyable type 'NC'}}
43
- _ = m [ keyPath: \. nc. data] // expected-error {{key path cannot refer to noncopyable type 'NC'}}
44
- _ = m [ keyPath: \. ncg] // expected-error {{key path cannot refer to noncopyable type 'V'}}
45
- _ = m [ keyPath: \. ncg. protocolProp] // expected-error {{key path cannot refer to noncopyable type 'V'}}
42
+ _ = m [ keyPath: \. nc]
43
+ // expected-error@-1 {{key path cannot refer to noncopyable type 'M<V>'}}
44
+ // expected-error@-2 {{key path cannot refer to noncopyable type 'NC'}}
45
+ _ = m [ keyPath: \. nc. data]
46
+ // expected-error@-1 {{key path cannot refer to noncopyable type 'M<V>'}}
47
+ _ = m [ keyPath: \. ncg]
48
+ // expected-error@-1 {{key path cannot refer to noncopyable type 'M<V>'}}
49
+ // expected-error@-2 {{key path cannot refer to noncopyable type 'V'}}
50
+ _ = m [ keyPath: \. ncg. protocolProp]
51
+ // expected-error@-1 {{key path cannot refer to noncopyable type 'M<V>'}}
46
52
_ = m [ keyPath: \. string]
53
+ // expected-error@-1 {{key path cannot refer to noncopyable type 'M<V>'}}
47
54
48
55
let b = Box ( NC ( ) )
49
56
_ = b. with ( \. data)
Original file line number Diff line number Diff line change @@ -945,7 +945,9 @@ func testKeyPathHole() {
945
945
946
946
func f( _ i: Int ) { }
947
947
f ( \. x) // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}} {{6-6=<#Root#>}}
948
+ // expected-error@-1 {{cannot convert value of type 'KeyPath<Root, Value>' to expected argument type 'Int'}}
948
949
f ( \. x. y) // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}} {{6-6=<#Root#>}}
950
+ // expected-error@-1 {{cannot convert value of type 'KeyPath<Root, Value>' to expected argument type 'Int'}}
949
951
950
952
func provideValueButNotRoot< T> ( _ fn: ( T ) -> String ) { } // expected-note 2 {{in call to function 'provideValueButNotRoot'}}
951
953
provideValueButNotRoot ( \. x) // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}}
You can’t perform that action at this time.
0 commit comments