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

Could anyone help me understand why I am getting this error: Pattern that the region based isolation checker does not understand how to check. Please file a bug.

@main
enum SE_NNN {
    static func main () async {
        class U {
            var v = 0
        }
        
        let u = U ()

        Task {@MainActor in // Okay
            u.v += 2
        }
        
        Task {@MyGlobalActor in // Error: Pattern that the region based isolation checker does not understand how to check. Please file a bug
            u.v += 3
        }
        
        u.v += 5

        print (u.v)
    }
}

@globalActor
actor MyGlobalActor {
    static let shared = MyGlobalActor()
}

This doesn’t directly answer the question, because honestly I’m just not sure.

But I do know that many of these have been addressed in 6.1, so it may be worth giving that toolchain a shot. And if that does not work, filing a GitHub issue would be great!

1 Like

For what it's worth, when I compile the code with a semi-current main branch toolchain (2024-12-13, to be exact) I get this error:

error: sending 'u' risks causing data races
note: 'u' is captured by a global actor 'MyGlobalActor'-isolated closure. global actor 'MyGlobalActor'-isolated uses in closure may race against later nonisolated uses

$ swiftc --version
Apple Swift version 6.2-dev (LLVM be8c96d78337932, Swift 0bbaa3519b62071)
Target: arm64-apple-macosx15.0

$ swiftc -swift-version 6 -parse-as-library code.swift
code.swift:17:13: error: sending 'u' risks causing data races
15 |
16 |         Task {@MyGlobalActor in // Error: Pattern that the region based isolation checker does not understand how to check. Please file a bug
17 |             u.v += 3
   |             |- error: sending 'u' risks causing data races
   |             `- note: 'u' is captured by a global actor 'MyGlobalActor'-isolated closure. global actor 'MyGlobalActor'-isolated uses in closure may race against later nonisolated uses
18 |         }
19 |
20 |         u.v += 5
   |         `- note: access can happen concurrently
21 |
22 |         print (u.v)
3 Likes

Thank you. That was the kind of error message I was expecting, but I got confused by the error message which Swift 6 compiler had emitted.

1 Like