|
| 1 | +// RUN: %empty-directory(%t/src) |
| 2 | +// RUN: split-file %s %t/src |
| 3 | + |
| 4 | +/// Build the library A |
| 5 | +// RUN: %target-swift-frontend -emit-module %t/src/A.swift \ |
| 6 | +// RUN: -module-name A -swift-version 5 \ |
| 7 | +// RUN: -default-isolation MainActor \ |
| 8 | +// RUN: -enable-library-evolution \ |
| 9 | +// RUN: -emit-module-path %t/A.swiftmodule \ |
| 10 | +// RUN: -emit-module-interface-path %t/A.swiftinterface |
| 11 | + |
| 12 | +// RUN: %FileCheck %t/src/A.swift < %t/A.swiftinterface |
| 13 | + |
| 14 | +// Build the client using module |
| 15 | +// RUN: %target-swift-frontend -typecheck -verify -verify-ignore-unrelated -I %t -primary-file %t/src/Client.swift |
| 16 | + |
| 17 | +// RUN: rm %t/A.swiftmodule |
| 18 | + |
| 19 | +// Re-build the client using interface |
| 20 | +// RUN: %target-swift-frontend -typecheck -verify -verify-ignore-unrelated -I %t -primary-file %t/src/Client.swift |
| 21 | + |
| 22 | +// REQUIRES: concurrency |
| 23 | + |
| 24 | +//--- A.swift |
| 25 | + |
| 26 | +// CHECK: @_Concurrency.MainActor @preconcurrency public protocol P |
| 27 | +public protocol P { |
| 28 | +} |
| 29 | + |
| 30 | +// CHECK: nonisolated public protocol Q : Swift.Sendable |
| 31 | +nonisolated public protocol Q: Sendable { |
| 32 | +} |
| 33 | + |
| 34 | +// CHECK: @_Concurrency.MainActor @preconcurrency public struct S : A.P { |
| 35 | +public struct S: P { |
| 36 | + // CHECK: @_Concurrency.MainActor @preconcurrency public func f() |
| 37 | + public func f() {} |
| 38 | + |
| 39 | + // CHECK: @_Concurrency.MainActor @preconcurrency public struct Inner { |
| 40 | + public struct Inner { |
| 41 | + // CHECK: @_Concurrency.MainActor @preconcurrency public init() |
| 42 | + public init() {} |
| 43 | + } |
| 44 | + // CHECK: } |
| 45 | +} |
| 46 | +// CHECK: } |
| 47 | + |
| 48 | +// CHECK: public struct R : A.Q { |
| 49 | +public struct R: Q { |
| 50 | + // CHECK: public struct Inner { |
| 51 | + public struct Inner { |
| 52 | + // CHECK: public init() |
| 53 | + public init() {} |
| 54 | + } |
| 55 | + // CHECK: } |
| 56 | + |
| 57 | + // CHECK: @_Concurrency.MainActor @preconcurrency public struct InnerIsolated : A.P { |
| 58 | + // CHECK: } |
| 59 | + public struct InnerIsolated: P {} |
| 60 | +} |
| 61 | +// CHECK: } |
| 62 | + |
| 63 | +// CHECK: @_Concurrency.MainActor @preconcurrency public func testGlobal() |
| 64 | +public func testGlobal() {} |
| 65 | + |
| 66 | +// CHECK: @_Concurrency.MainActor @preconcurrency public class C { |
| 67 | +public class C { |
| 68 | + // CHECK: @_Concurrency.MainActor @preconcurrency public init() |
| 69 | + public init() {} |
| 70 | + |
| 71 | + // CHECK: @_Concurrency.MainActor @preconcurrency public static var value: Swift.Int |
| 72 | + public static var value = 42 |
| 73 | + |
| 74 | + // CHECK: {{(@objc )?}} @_Concurrency.MainActor deinit |
| 75 | +} |
| 76 | +// CHECK: } |
| 77 | + |
| 78 | +// CHECK: @_Concurrency.MainActor @preconcurrency open class IsolatedDeinitTest { |
| 79 | +open class IsolatedDeinitTest { |
| 80 | + // CHECK: {{(@objc )?}} isolated deinit |
| 81 | + isolated deinit {} |
| 82 | +} |
| 83 | +// CHECK: } |
| 84 | + |
| 85 | + |
| 86 | +//--- Client.swift |
| 87 | +import A |
| 88 | + |
| 89 | +final class IsolatedDeinitChild: IsolatedDeinitTest {} // Ok |
| 90 | + |
| 91 | +nonisolated func testIsolation() { |
| 92 | + testGlobal() // expected-warning {{call to main actor-isolated global function 'testGlobal()' in a synchronous nonisolated context}} |
| 93 | + |
| 94 | + func test(s: S) { |
| 95 | + s.f() // expected-warning {{call to main actor-isolated instance method 'f()' in a synchronous nonisolated context}} |
| 96 | + } |
| 97 | + |
| 98 | + _ = S.Inner() // expected-warning {{call to main actor-isolated initializer 'init()' in a synchronous nonisolated context}} |
| 99 | + _ = R.Inner() // Ok |
| 100 | + |
| 101 | + _ = C() // expected-warning {{call to main actor-isolated initializer 'init()' in a synchronous nonisolated context}} |
| 102 | + _ = C.value // expected-warning {{main actor-isolated class property 'value' can not be referenced from a nonisolated context}} |
| 103 | +} |
0 commit comments