Skip to content

Commit 19be770

Browse files
authored
Merge pull request swiftlang#68303 from hborla/isolated-parameter-test-case
2 parents d5ab98d + 511add6 commit 19be770

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/Concurrency/isolated_parameters.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,32 @@ func isolatedClosures() {
319319
a.f()
320320
}
321321
}
322+
323+
// Test case for https://github.com/apple/swift/issues/62568
324+
func execute<ActorType: Actor>(
325+
on isolatedActor: isolated ActorType,
326+
task: @escaping @Sendable (isolated ActorType) -> Void)
327+
{
328+
// Compiler correctly allows this task to execute synchronously.
329+
task(isolatedActor)
330+
// Start a task that inherits the current execution context (i.e. that of the isolatedActor)
331+
Task {
332+
// 'await' is not not necessary because 'task' is synchronous.
333+
task(isolatedActor)
334+
}
335+
}
336+
337+
actor ProtectsDictionary {
338+
var dictionary: [String: String] = ["A": "B"]
339+
}
340+
341+
func getValues(
342+
forKeys keys: [String],
343+
from actor: isolated ProtectsDictionary
344+
) -> [String?] {
345+
// A non-escaping, synchronous closure cannot cross isolation
346+
// boundaries; it should be isolated to 'actor'.
347+
keys.map { key in
348+
actor.dictionary[key]
349+
}
350+
}

0 commit comments

Comments
 (0)