|
| 1 | +// RUN: %target-swift-frontend -swift-version 6 -verify -c %s |
| 2 | + |
| 3 | +// READ THIS! This file only contains tests that validate that the relevant |
| 4 | +// function subtyping rules for sending work. Please do not put other tests in |
| 5 | +// the file! |
| 6 | + |
| 7 | +// REQUIRES: concurrency |
| 8 | +// REQUIRES: asserts |
| 9 | + |
| 10 | +//////////////////////// |
| 11 | +// MARK: Declarations // |
| 12 | +//////////////////////// |
| 13 | + |
| 14 | +class NonSendableKlass {} |
| 15 | + |
| 16 | +protocol ProtocolWithSendingReqs { |
| 17 | + func sendingResult() -> sending NonSendableKlass // expected-note {{}} |
| 18 | + func nonSendingParam(_ x: NonSendableKlass) // expected-note {{}} |
| 19 | +} |
| 20 | + |
| 21 | +protocol ProtocolWithMixedReqs { |
| 22 | + func nonSendingParamAndSendingResult(_ x: NonSendableKlass) -> sending NonSendableKlass // expected-note 4{{}} |
| 23 | +} |
| 24 | + |
| 25 | +///////////////// |
| 26 | +// MARK: Tests // |
| 27 | +///////////////// |
| 28 | + |
| 29 | +struct MatchSuccess : ProtocolWithSendingReqs, ProtocolWithMixedReqs { |
| 30 | + func sendingResult() -> sending NonSendableKlass { fatalError() } |
| 31 | + func nonSendingParam(_ x: NonSendableKlass) -> () { fatalError() } |
| 32 | + func nonSendingParamAndSendingResult(_ x: NonSendableKlass) -> sending NonSendableKlass { fatalError() } |
| 33 | +} |
| 34 | + |
| 35 | +struct FailToMatch : ProtocolWithSendingReqs, ProtocolWithMixedReqs { // expected-error 2{{}} |
| 36 | + func sendingResult() -> NonSendableKlass { fatalError() } |
| 37 | + // expected-note @-1 {{candidate has non-matching type '() -> NonSendableKlass'}} |
| 38 | + func nonSendingParam(_ x: sending NonSendableKlass) -> () { fatalError() } |
| 39 | + // expected-note @-1 {{candidate has non-matching type '(sending NonSendableKlass) -> ()'}} |
| 40 | + func nonSendingParamAndSendingResult(_ x: sending NonSendableKlass) -> NonSendableKlass { fatalError() } |
| 41 | + // expected-note @-1 {{candidate has non-matching type '(sending NonSendableKlass) -> NonSendableKlass'}} |
| 42 | +} |
| 43 | + |
| 44 | +struct FailToMatch2 : ProtocolWithMixedReqs { // expected-error {{}} |
| 45 | + func nonSendingParamAndSendingResult(_ x: sending NonSendableKlass) -> NonSendableKlass { fatalError() } |
| 46 | + // expected-note @-1 {{candidate has non-matching type '(sending NonSendableKlass) -> NonSendableKlass'}} |
| 47 | +} |
| 48 | + |
| 49 | +struct FailToMatch3 : ProtocolWithMixedReqs { // expected-error {{}} |
| 50 | + func nonSendingParamAndSendingResult(_ x: NonSendableKlass) -> NonSendableKlass { fatalError() } |
| 51 | + // expected-note @-1 {{candidate has non-matching type '(NonSendableKlass) -> NonSendableKlass'}} |
| 52 | +} |
| 53 | + |
| 54 | +struct FailToMatch4 : ProtocolWithMixedReqs { // expected-error {{}} |
| 55 | + func nonSendingParamAndSendingResult(_ x: sending NonSendableKlass) -> sending NonSendableKlass { fatalError() } |
| 56 | + // expected-note @-1 {{candidate has non-matching type '(sending NonSendableKlass) -> sending NonSendableKlass'}} |
| 57 | +} |
0 commit comments