Files
swift-mirror/test/ClangImporter/sending.swift
Daniel Rodríguez Troitiño ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00

41 lines
1.5 KiB
Swift

// RUN: %target-swift-frontend -swift-version 6 -disable-availability-checking -emit-sil -o /dev/null %s -parse-as-library -enable-experimental-feature SendingArgsAndResults -verify -import-objc-header %S/Inputs/sending.h
// REQUIRES: concurrency
// REQUIRES: swift_feature_SendingArgsAndResults
////////////////////////
// MARK: Declarations //
////////////////////////
// Make our non sendable c struct non-Sendable
@available(*, unavailable)
extension NonSendableCStruct: Sendable {}
@MainActor func sendToMain<T>(_ t: T) async {}
func useValue<T>(_ t: T) {}
/////////////////
// MARK: Tests //
/////////////////
func funcTestSendingResult() async {
let x = NonSendableCStruct()
let y = sendUserDefinedFromGlobalFunction(x)
await sendToMain(x)
useValue(y)
// Just to show that without the sending param, we generate diagnostics.
let x2 = NonSendableCStruct()
let y2 = returnUserDefinedFromGlobalFunction(x2)
await sendToMain(x2) // expected-error {{sending 'x2' risks causing data races}}
// expected-note @-1 {{sending 'x2' to main actor-isolated global function 'sendToMain' risks causing data races between main actor-isolated and local nonisolated uses}}
useValue(y2) // expected-note {{access can happen concurrently}}
}
func funcTestSendingArg() async {
let x = NonSendableCStruct()
sendUserDefinedIntoGlobalFunction(x) // expected-error {{sending 'x' risks causing data races}}
// expected-note @-1 {{'x' used after being passed as a 'sending' parameter}}
useValue(x) // expected-note {{access can happen concurrently}}
}