Files
swift-mirror/validation-test/Sema/SwiftUI/rdar76252310.swift
Michael Gottesman b8cf5aeb34 Updates for 6.2.
These were changes that were not updated in the previous commit due to merge conflict
resolution or that the test itself was not in 6.2.
2025-05-23 10:33:58 -07:00

53 lines
1.4 KiB
Swift

// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5 -strict-concurrency=complete
// REQUIRES: objc_interop
// REQUIRES: OS=macosx
import SwiftUI
@MainActor
class Visibility: ObservableObject {
nonisolated init() {}
@Published var yes = false // some nonsense
}
struct CoffeeTrackerView: View {
nonisolated init() {}
@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 {
let view = CoffeeTrackerView() // synthesized 'init' is 'nonisolated'
// expected-warning@+2 {{non-Sendable type 'some View' of property 'body' cannot exit main actor-isolated context}}
// expected-warning@+1 {{main actor-isolated property 'body' cannot be accessed from outside of the actor}} {{7-7=await }}
_ = view.body
// expected-warning@+1 {{main actor-isolated property 'showDrinkList' cannot be accessed from outside of the actor}} {{7-7=await }}
_ = view.showDrinkList
_ = view.storage
}