Skip to content

allow @_unavailableFromAsync on computed properties #85789

@lukaskollmer

Description

@lukaskollmer

Motivation

swift currently has the (private) @_unavailableFromAsync attribute, which can be used to mark a function as not being available from async contexts.

this attribute can only be used with functions, but not with getters for computed properties.
for example, this program would not compile (regardless of whether the attribute is placed before or after the get or is applied to the variable as a whole):

struct S {
    var p: Int {
        @_unavailableFromAsync get {
            12
        }
    }
}

the specific motivation this is coming from is an API which uses macros to generate get/set accessors for computed static properties which implement a synchronization mechanism, and therefore should not be used from async code.

Proposed solution

it might be worthwhile to consider allowing using this attribute with computed properties as well, especially given the fact that these are essentially just implicit function calls.

Alternatives considered

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureA feature request or implementationtriage 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