Skip to content

Actor boundary warning for @TaskLocal values #62220

@mroi

Description

@mroi

Description
I am getting this warning with Version 14.1 (14B47b):

actor Test {

	@TaskLocal static var local: Int?

	func run() async {
		await Self.$local.withValue(42) {  // ⚠️
			await work()
		}
	}

	func work() async {
		print("Hello \(Self.local ?? 0)")
	}
}

await Test().run()

warning: non-sendable type '() async throws -> ()' exiting actor-isolated context in call to non-isolated instance method 'withValue(_:operation:file:line:)' cannot cross actor boundary

Steps to reproduce

  1. copy the above code into a file test.swift
  2. run swift -warn-concurrency test.swift

Expected behavior
The code should not produce a warning if it is legal code.

Environment

  • swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)
  • Target: x86_64-apple-macosx13.0
  • Xcode 14.1, Build version 14B47b

Additional context
Mentioned on Swift forum.

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.concurrencyFeature: umbrella label for concurrency language featuresstandard libraryArea: Standard library umbrella

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions