swiftlang / swift

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

Pattern that the region-based isolation checker does not understand how to check #75441

Open samsonjs opened 3 months ago

samsonjs commented 3 months ago

Description

In Xcode 16.0 beta 4 there's a new compiler error for code that used to build in previous betas.

Possibly related to #75439

Reproduction

actor A {
    var things: [String]

    init() {
        things = []
    }
}

@MainActor class B {
    let a = A()

    var stuff: [String] = []

    func doSomething() async {
        // ❌ Pattern that the region based isolation checker does not understand how to check. Please file a bug
        stuff = await a.things
    }
}

Expected behavior

This worked fine in previous betas of Xcode 16.0. It should compile without issues.

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

Using a method instead of directly accessing the var works just fine.

actor A {
    var things: [String]

    init() {
        things = []
    }

    func getThings() -> [String] { things }
}

@MainActor class B {
    let a = A()

    var stuff: [String] = []

    func doSomething() async {
        // ✅ works fine with methods
        stuff = await a.getThings()
    }
}
ktoso commented 3 months ago

@gottesmm has been solving these recently