mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
54 lines
2.1 KiB
Swift
54 lines
2.1 KiB
Swift
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5 -strict-concurrency=targeted
|
|
|
|
// REQUIRES: objc_interop
|
|
// REQUIRES: OS=macosx
|
|
|
|
import SwiftUI
|
|
|
|
class Visibility: ObservableObject { // expected-note 2{{class 'Visibility' does not conform to the 'Sendable' protocol}}
|
|
@Published var yes = false // some nonsense
|
|
}
|
|
|
|
struct CoffeeTrackerView: View { // expected-note{{consider making struct 'CoffeeTrackerView' conform to the 'Sendable' protocol}}
|
|
@ObservedObject var showDrinkList: Visibility = Visibility()
|
|
|
|
var storage: Visibility = Visibility()
|
|
|
|
var body: some View {
|
|
VStack {
|
|
Button(action: {}) {
|
|
Image(self.showDrinkList.yes ? "add-coffee" : "add-tea")
|
|
.renderingMode(.template)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
func fromMainActor() async {
|
|
let view = CoffeeTrackerView()
|
|
_ = view.body
|
|
_ = view.showDrinkList
|
|
_ = view.storage
|
|
}
|
|
|
|
|
|
func fromConcurrencyAware() async {
|
|
// expected-note@+3 {{calls to initializer 'init()' from outside of its actor context are implicitly asynchronous}}
|
|
// expected-error@+2 {{expression is 'async' but is not marked with 'await'}}
|
|
// expected-warning@+1 {{non-sendable type 'CoffeeTrackerView' returned by call to main actor-isolated function cannot cross actor boundary}}
|
|
let view = CoffeeTrackerView()
|
|
|
|
// expected-note@+3 {{property access is 'async'}}
|
|
// expected-warning@+2 {{non-sendable type 'some View' in implicitly asynchronous access to main actor-isolated property 'body' cannot cross actor boundary}}
|
|
// expected-error@+1 {{expression is 'async' but is not marked with 'await'}}
|
|
_ = view.body
|
|
|
|
// expected-note@+3 {{property access is 'async'}}
|
|
// expected-warning@+2 {{non-sendable type 'Visibility' in implicitly asynchronous access to main actor-isolated property 'showDrinkList' cannot cross actor boundary}}
|
|
// expected-error@+1 {{expression is 'async' but is not marked with 'await'}}
|
|
_ = view.showDrinkList
|
|
|
|
_ = await view.storage // expected-warning {{non-sendable type 'Visibility' in implicitly asynchronous access to main actor-isolated property 'storage' cannot cross actor boundary}}
|
|
}
|