Files
swift-mirror/test/Concurrency/nonisolated_access.swift
Allan Shortlidge c02fc4724d Tests: Remove -disable-availability-checking from many Concurrency tests.
Instead, use the `%target-swift-5.1-abi-triple` substitution to compile the tests
for deployment to the minimum OS versions required for use of _Concurrency APIs.
2024-10-18 16:21:51 -07:00

49 lines
1.1 KiB
Swift

// RUN: %empty-directory(%t/src)
// RUN: split-file %s %t/src
/// Build the library A
// RUN: %target-swift-frontend -emit-module %t/src/A.swift \
// RUN: -target %target-swift-5.1-abi-triple -verify \
// RUN: -module-name A -swift-version 6 \
// RUN: -emit-module-path %t/A.swiftmodule
// Build the client
// RUN: %target-swift-frontend -emit-module %t/src/Client.swift \
// RUN: -target %target-swift-5.1-abi-triple -verify \
// RUN: -module-name Client -I %t -swift-version 6 \
// RUN: -emit-module-path %t/Client.swiftmodule
// REQUIRES: concurrency
//--- A.swift
@MainActor
public protocol P {}
@frozen
public struct ImplicitlySendable {
nonisolated public var prop: Bool = true
nonisolated public init() {}
}
public struct S: P {
nonisolated public var x: Int = 0
public var y: Int = 1
nonisolated public init() {}
}
//--- Client.swift
import A
actor A {
func test() {
var s = S()
s.x += 0 // okay
// expected-error@+1 {{main actor-isolated property 'y' can not be mutated on a nonisolated actor instance}}
s.y += 1
var sendable = ImplicitlySendable()
sendable.prop = false // okay
}
}