|
| 1 | +// RUN: %target-typecheck-verify-swift -swift-version 5 -verify-additional-prefix swift5- |
| 2 | +// RUN: %target-typecheck-verify-swift -swift-version 5 -strict-concurrency=complete -verify-additional-prefix swift6- |
| 3 | +// RUN: %target-typecheck-verify-swift -swift-version 6 -verify-additional-prefix swift6- |
| 4 | + |
| 5 | +protocol P { |
| 6 | + @preconcurrency var prop: [String: any Sendable] { get set } |
| 7 | + // expected-swift5-note@-1 3 {{expected sendability to match requirement here}} |
| 8 | + // expected-swift6-note@-2 3 {{protocol requires property 'prop' with type '[String : any Sendable]'}} |
| 9 | + @preconcurrency func reqFn(_: [String: any Sendable], _: @Sendable ((any Sendable)?) -> Void) |
| 10 | + // expected-swift5-note@-1 2 {{expected sendability to match requirement here}} |
| 11 | + // expected-swift6-note@-2 2 {{protocol requires function 'reqFn' with type '([String : any Sendable], @Sendable ((any Sendable)?) -> Void) -> ()'}} |
| 12 | +} |
| 13 | + |
| 14 | +struct S1 : P { // expected-swift6-error {{type 'S1' does not conform to protocol 'P'}} expected-swift6-note {{add stubs for conformance}} |
| 15 | + var prop: [String: Any] = [:] |
| 16 | + // expected-swift5-warning@-1 {{sendability of function types in property 'prop' does not match requirement in protocol 'P'; this is an error in the Swift 6 language mode}} |
| 17 | + // expected-swift6-note@-2 {{candidate has non-matching type '[String : Any]'}} |
| 18 | + func reqFn(_: [String: Any], _: (Any?) -> Void) {} |
| 19 | + // expected-swift5-warning@-1 {{sendability of function types in instance method 'reqFn' does not match requirement in protocol 'P'; this is an error in the Swift 6 language mode}} |
| 20 | + // expected-swift6-note@-2 {{candidate has non-matching type '([String : Any], (Any?) -> Void) -> ()'}} |
| 21 | +} |
| 22 | + |
| 23 | +struct S2 : P { // expected-swift6-error {{type 'S2' does not conform to protocol 'P'}} expected-swift6-note {{add stubs for conformance}} |
| 24 | + var prop: [String: Any] = [:] |
| 25 | + // expected-swift5-warning@-1 {{sendability of function types in property 'prop' does not match requirement in protocol 'P'; this is an error in the Swift 6 language mode}} |
| 26 | + // expected-swift6-note@-2 {{candidate has non-matching type '[String : Any]'}} |
| 27 | + |
| 28 | + func reqFn(_: [String: Any], _: ((any Sendable)?) -> Void) {} |
| 29 | + // expected-swift5-warning@-1 {{sendability of function types in instance method 'reqFn' does not match requirement in protocol 'P'; this is an error in the Swift 6 language mode}} |
| 30 | + // expected-swift6-note@-2 {{candidate has non-matching type '([String : Any], ((any Sendable)?) -> Void) -> ()'}} |
| 31 | +} |
| 32 | + |
| 33 | +struct S3 : P { // expected-swift6-error {{type 'S3' does not conform to protocol 'P'}} expected-swift6-note {{add stubs for conformance}} |
| 34 | + var prop: [String: Any] = [:] |
| 35 | + // expected-swift5-warning@-1 {{sendability of function types in property 'prop' does not match requirement in protocol 'P'; this is an error in the Swift 6 language mode}} |
| 36 | + // expected-swift6-note@-2 {{candidate has non-matching type '[String : Any]'}} |
| 37 | + |
| 38 | + func reqFn(_: [String: any Sendable], _: ((any Sendable)?) -> Void) {} // Ok |
| 39 | +} |
| 40 | + |
| 41 | +protocol Q { |
| 42 | + var prop: [String: [String: any Sendable]] { get set } |
| 43 | + // expected-note@-1 {{protocol requires property 'prop' with type '[String : [String : any Sendable]]'}} |
| 44 | + |
| 45 | + func test(_: [() -> (any Sendable)?]) |
| 46 | + // expected-note@-1 {{protocol requires function 'test' with type '([() -> (any Sendable)?]) -> ()'}} |
| 47 | +} |
| 48 | + |
| 49 | +struct S4 : Q { // expected-error {{type 'S4' does not conform to protocol 'Q'}} expected-note {{add stubs for conformance}} |
| 50 | + var prop: [String: [String: Any]] = [:] |
| 51 | + // expected-note@-1 {{candidate has non-matching type '[String : [String : Any]]'}} |
| 52 | + |
| 53 | + func test(_: [() -> Any?]) {} |
| 54 | + // expected-note@-1 {{candidate has non-matching type '([() -> Any?]) -> ()'}} |
| 55 | +} |
0 commit comments