Skip to content

@TaskLocal macro does not specify access control for projected value properties #73557

@hyp

Description

@hyp

Description

After #73078 the @TaskLocal macro (which used to be a property wrapper) generates the projected value property without specifying access control, making such property internal, and inaccessible from another module.

For example, we are using this utility module:
https://github.com/pointfreeco/xctest-dynamic-overlay/blob/698be4131e778c2dd15ea47be0523280328bc2db/Sources/XCTestDynamicOverlay/XCTFail.swift#L4

public struct XCTFailContext: Sendable {
  @TaskLocal public static var current: Self?
}

and then a consumer module is accessing its projected value:

XCTFailContext.$current.withValue(...) { ... }

After this change this code no longer compiles, as it complains that $current is now internal.

According to the property wrapper rules the $current projected value property should be public and accessible. Is that correct, or are TaskLocal properties special?

Reproduction

import XCTestDynamicOverlay

func test() {
  XCTFailContext.$current.withValue(XCTFailContext(file: "abc", line: 123)) {
  }
}

Expected behavior

This sample should compile, but instead it errors out:

      XCTFailContext.$current.withValue(XCTFailContext(file: "abc", line: 123)) {
|                            `- error: '$current' is inaccessible due to 'internal' protection level

Environment

Swift main

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions