Search code examples
swift

Why is this a circular reference in Swift 5.10?


Why does extension A: A.Nested.Doable (last line) cause a circular reference in the following Swift 5.10 code?

class Parent1 {
    
}

class Parent2 {
    
}

class A: Parent1 {

}

extension A { class Nested: Parent2 {
    
} }

extension A.Nested { protocol Doable {
    
} }

extension A: A.Nested.Doable {
    
}

If don't make A.Nested inherit from anything, then no circular reference is found in the code by Xcode.

Xcode 15.3, MacBook Air M1 8GB, macOS Sonoma 14.4.1.


Solution

  • If it helps, it compiles when you put class A together without adding the protocol conformance via extension:

    class A: Parent1, A.Nested.Doable {
        class Nested: Parent2 {
            protocol Doable {
    
            }
        }
    }