Skip to content

Commit d4f0efc

Browse files
committed
Add cross-module tests for default isolation behavior
1 parent 9f7dff0 commit d4f0efc

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public protocol ImportedSendableProto: Sendable { }
2+
3+
@MainActor public struct ImportedStruct: ImportedSendableProto { }
4+
5+
public struct ImportedOtherStruct { }
6+
7+
public protocol ImportedP { }

test/Concurrency/assume_mainactor_typechecker_errors.swift

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
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-
35

46
// READ THIS! This test is meant to check the specific isolation when
57
// `-default-isolation` is set to `MainActor` in combination with validating
68
// behavior around explicitly non-Sendable types that trigger type checker
79
// specific errors. Please do not put other types of tests in here.
810

11+
import implicit_nonisolated_things
12+
913
// Fake Sendable Data
1014
class SendableData : @unchecked Sendable {}
1115
// expected-swift5-note@-1 {{calls to initializer 'init()' from outside of its actor context are implicitly asynchronous}}
@@ -82,7 +86,7 @@ func testTaskDetached() async {
8286

8387
// @MainActor
8488
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}}
8690
}
8791

8892
nonisolated func testMemberOfInt(i: Int) {
@@ -127,6 +131,34 @@ struct MyP: P {
127131
}
128132
}
129133

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+
130162
// https://github.com/swiftlang/swift/issues/82168 -
131163
nonisolated protocol OtherP {
132164
associatedtype AT

0 commit comments

Comments
 (0)