Cycle reference since changing to Default Actor Isolation Main Actor in nested structs

Hey guys,

since the new default actor isolation, i wanted to try to set my project to MainActor default actor.

After changing the setting i was getting basically an error for every struct that has Codable in it.

My code:

extension MyTestActor {
    struct Structs {}
}

extension MyTestActor.Structs {
    struct MyTestStruct: Codable {
        var test: String
    }
}

for this code i was getting this error

Circular referenceSourceKit
Test.swift(19, 12): Through reference here
Test.swift(19, 12): Through reference here
Test.swift(19, 12): Through reference here
Conformance of 'MyTestActor.Structs.MyTestStruct' to protocol 'Encodable' crosses into main actor-isolated code and can cause data racesSourceKitconformance-isolation
Test.swift(19, 22): Isolate this conformance to the main actor with '@MainActor'
Test.swift(19, 22): Turn data races into runtime errors with '@preconcurrency'
Test.swift(19, 22): Main actor-isolated instance method 'encode(to:)' cannot satisfy nonisolated requirement (Mana.MyTestActor.Structs.MyTestStruct.encode)

although what is funny.. if i change my code to this code, it suddenly is not throwing any error anymore, although i just removed the nesting of the structs.. why does this happen?

extension MyTestActor {
    struct Structs {}
}

extension MyTestActor {
    struct MyTestStruct: Codable {
        var test: String
    }
}
1 Like

This was likely reported in Codable conformance throws Circular reference compile error when default isolation is enabled · Issue #82200 · swiftlang/swift · GitHub, which is closed. If Xcode 26 beta 2 still has the issue, you can wait for beta 3 or 4 (we never know), or look closely and open a new issue if you think that your scenario is distinct from the one that was originally reported.

1 Like

Thanks, i tried it with XCode 26 Beta 2 but the issue is still there. I will open a new issue and maybe someone will tell me if i do something wrong or if its a bug :slight_smile: Thank you

The fix is not in Xcode 26 beta 2, but it is in the 6.2 development snapshots on swift.org.

2 Likes