swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.3k stars 10.34k forks source link

False positive warning about closure isolation but only when argument label is omitted #75522

Open groue opened 1 month ago

groue commented 1 month ago

Description

The compiler changes its diagnostic depending on whether a closure argument is declared with or without argument label.

Reproduction

struct SUT {
    func run1(completion: sending @escaping () -> Void) { }
    func run2(_ completion: sending @escaping () -> Void) { }
}

@MainActor
func test_run() {
    let sut = SUT()

    // No warning
    sut.run1 { }

    // Main actor-isolated value of type '() -> ()' passed as a strongly
    // transferred parameter; later accesses could race
    sut.run2 { }
}

This is very confusing.

Expected behavior

No warning in both cases.

Environment

% swiftc -version swift-driver version: 1.112.3 Apple Swift version 6.0 (swiftlang-6.0.0.6.8 clang-1600.0.23.1) Target: arm64-apple-macosx14.0

Additional information

No response

groue commented 1 month ago

Related: #75521