Skip to content

Compiler fails to prevent data race in generic function #85107

@rayx

Description

@rayx

Description

Compiler produces diagnostics for the following (as expected):

func test() {
    var result = 0
    Task {
        result = 0
    }
    print(result) // note: access can happen concurrently
}

but fails to produces diagnostics for similar generic code:

func test<T: Sendable>(t: T) {
    var result: T = t
    Task {
        result = t
    }
    print(result)
}

test(t: 1)

Reproduction

See above

Expected behavior

The generic function should fails to compile too.

Environment

I used x86-64 swiftc nightly on godbolt.

Additional information

No response

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.concurrencyFeature: umbrella label for concurrency language features

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions