|
1 |
| -// RUN: %target-swift-frontend -swift-version 5 -emit-sil -default-isolation MainActor %s -verify -verify-additional-prefix swift5- |
2 |
| -// RUN: %target-swift-frontend -swift-version 6 -emit-sil -default-isolation MainActor %s -verify -verify-additional-prefix swift6- |
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-swift-frontend -emit-module -swift-version 6 -module-name implicit_nonisolated_things -o %t/implicit_nonisolated_things.swiftmodule %S/Inputs/implicit_nonisolated_things.swift |
| 3 | +// RUN: %target-swift-frontend -I %t -swift-version 5 -emit-sil -default-isolation MainActor %s -verify -verify-additional-prefix swift5- |
| 4 | +// RUN: %target-swift-frontend -I %t -swift-version 6 -emit-sil -default-isolation MainActor %s -verify -verify-additional-prefix swift6- |
3 | 5 |
|
4 | 6 | // READ THIS! This test is meant to check the specific isolation when
|
5 | 7 | // `-default-isolation` is set to `MainActor` in combination with validating
|
6 | 8 | // behavior around explicitly non-Sendable types that trigger type checker
|
7 | 9 | // specific errors. Please do not put other types of tests in here.
|
8 | 10 |
|
| 11 | +import implicit_nonisolated_things |
| 12 | + |
9 | 13 | // Fake Sendable Data
|
10 | 14 | class SendableData : @unchecked Sendable {}
|
11 | 15 | // expected-swift5-note@-1 {{calls to initializer 'init()' from outside of its actor context are implicitly asynchronous}}
|
@@ -82,7 +86,7 @@ func testTaskDetached() async {
|
82 | 86 |
|
83 | 87 | // @MainActor
|
84 | 88 | extension Int {
|
85 |
| - func memberOfInt() { } // expected-note 2{{calls to instance method 'memberOfInt()' from outside of its actor context are implicitly asynchronous}} |
| 89 | + func memberOfInt() { } // expected-note 3{{calls to instance method 'memberOfInt()' from outside of its actor context are implicitly asynchronous}} |
86 | 90 | }
|
87 | 91 |
|
88 | 92 | nonisolated func testMemberOfInt(i: Int) {
|
@@ -127,6 +131,34 @@ struct MyP: P {
|
127 | 131 | }
|
128 | 132 | }
|
129 | 133 |
|
| 134 | +// Above tests for imported types |
| 135 | +extension ImportedStruct: @retroactive CustomStringConvertible { |
| 136 | + public var description: String { |
| 137 | + 17.memberOfInt() // okay, on main actor |
| 138 | + return "hello" |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +extension ImportedOtherStruct { |
| 143 | + func f() { |
| 144 | + 17.memberOfInt() // okay, on main actor |
| 145 | + } |
| 146 | +} |
| 147 | + |
| 148 | +nonisolated |
| 149 | +extension ImportedOtherStruct { |
| 150 | + func g() { |
| 151 | + 17.memberOfInt() // expected-swift5-warning{{call to main actor-isolated instance method 'memberOfInt()' in a synchronous nonisolated context}} |
| 152 | + // expected-swift6-error@-1{{call to main actor-isolated instance method 'memberOfInt()' in a synchronous nonisolated context}} |
| 153 | + } |
| 154 | +} |
| 155 | + |
| 156 | +struct MyImportedP: ImportedP { |
| 157 | + func g() { |
| 158 | + 17.memberOfInt() // okay, on main actor |
| 159 | + } |
| 160 | +} |
| 161 | + |
130 | 162 | // https://github.com/swiftlang/swift/issues/82168 -
|
131 | 163 | nonisolated protocol OtherP {
|
132 | 164 | associatedtype AT
|
|
0 commit comments