Skip to content

Nonisolated nonsending closure called from nonisolated nonsending function does not inherit caller actor #83812

@AnthonyLatsis

Description

@AnthonyLatsis

Description

No response

Reproduction

nonisolated(nonsending) func g() async {
  MainActor.assertIsolated()
}

nonisolated(nonsending)
func f() async {
  await g() // okay
  let closure = g 
  await closure() // boom
}

@main struct Foo {
  static func main() async throws {
    await f()
  }
}

Expected behavior

g does not switch off the main actor.

Environment

Apple Swift version 6.2 (swiftlang-6.2.0.19.8 clang-1700.3.19.1)

Additional information

No response

Metadata

Metadata

Assignees

Labels

SILGenArea → compiler: The SIL generation stageactor isolationFeature → concurrency: Actor isolationcompilerThe Swift compiler itselfconcurrencyFeature: umbrella label for concurrency language featuresswift 6.2unexpected behaviorBug: Unexpected behavior or incorrect output

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions