Files
swift-mirror/test/Concurrency/nonisolated_inherits_isolation_sema.swift
Michael Gottesman 3ed4059a60 [sema] Change non-sendable -> non-Sendable in diagnostics.
This matches send non sendable but importantly also makes it clear that we are
talking about something that doesn't conform to the Sendable protocol which is
capitalized.

rdar://151802975
2025-05-22 11:37:58 -07:00

29 lines
771 B
Swift

// RUN: %target-typecheck-verify-swift -swift-version 6 -enable-upcoming-feature NonisolatedNonsendingByDefault -parse-as-library
// REQUIRES: asserts
// REQUIRES: concurrency
// REQUIRES: swift_feature_NonisolatedNonsendingByDefault
class NonSendable {} // expected-note {{}}
@MainActor var global = NonSendable()
@MainActor
struct MainActorIsolatedStruct {
init() {}
func syncMethod() {}
func asyncMethod() {}
}
struct NonisolatedStruct {
// Validate we can still not access global state.
func asyncMethod() async {
let _ = await global // expected-error {{non-Sendable type 'NonSendable' of var 'global' cannot exit main actor-isolated context}}
let x = await MainActorIsolatedStruct()
await x.syncMethod()
await x.asyncMethod()
}
}